├── .babelrc ├── .eslintrc.json ├── .gitignore ├── .vscode └── settings.json ├── README.md ├── package-lock.json ├── package.json ├── src ├── components │ ├── accessories │ │ ├── BinarySensorCard │ │ │ ├── BinarySensorCard.md │ │ │ ├── BinarySensorCard.tsx │ │ │ └── index.ts │ │ ├── CameraCard │ │ │ ├── CameraCard.md │ │ │ ├── CameraCard.tsx │ │ │ ├── CameraCardPlaceholderLoading.tsx │ │ │ ├── CameraCardPlaceholderOffline.tsx │ │ │ └── index.ts │ │ ├── LightCard │ │ │ ├── LightCard.md │ │ │ ├── LightCard.tsx │ │ │ ├── LightCardModal.tsx │ │ │ └── index.ts │ │ ├── SwitchCard │ │ │ ├── SwitchCard.md │ │ │ ├── SwitchCard.tsx │ │ │ └── index.ts │ │ ├── ThermostatCard │ │ │ ├── ThermostatCard.md │ │ │ ├── ThermostatCard.tsx │ │ │ ├── ThermostatCardModal.tsx │ │ │ └── index.ts │ │ └── index.ts │ ├── common │ │ ├── Slider.tsx │ │ ├── Switch.tsx │ │ ├── TemperatureIcon.tsx │ │ ├── cards │ │ │ ├── AccessoryCard.tsx │ │ │ ├── Card.tsx │ │ │ └── index.ts │ │ ├── hooks │ │ │ ├── index.ts │ │ │ ├── useBinarySensorIcon.ts │ │ │ ├── useBinarySensorLabel.ts │ │ │ ├── useLoadImage.ts │ │ │ ├── useModalHelper.ts │ │ │ ├── useSwitchIcon.ts │ │ │ └── useSwitchLabel.ts │ │ ├── index.ts │ │ ├── modals │ │ │ ├── Modal.tsx │ │ │ ├── ModalHeader.tsx │ │ │ └── index.ts │ │ └── types.tsx │ ├── icons │ │ ├── index.md │ │ └── index.tsx │ ├── index.ts │ ├── layout │ │ ├── SectionLayout │ │ │ ├── SectionLayout.md │ │ │ ├── SectionLayout.tsx │ │ │ ├── Title.tsx │ │ │ └── index.ts │ │ └── index.ts │ └── scenes │ │ ├── SceneCard │ │ ├── SceneCard.md │ │ ├── SceneCard.tsx │ │ └── index.ts │ │ └── index.ts ├── index.ts ├── module.d.ts ├── resources │ └── icons │ │ ├── accessories │ │ ├── contact-closed-large@2x.png │ │ ├── contact-open-large@2x.png │ │ ├── door-closed-large@2x.png │ │ ├── door-open-large@2x.png │ │ ├── light-bulb.svg │ │ ├── lock-secured-large@2x.png │ │ ├── lock-unsecured-large@2x.png │ │ ├── motion-off-large@2x.png │ │ ├── motion-on-large@2x.png │ │ ├── outlet-off-large@2x.png │ │ ├── outlet-on-large@2x.png │ │ ├── switch-off-large@2x.png │ │ ├── switch-on-large@2x.png │ │ ├── window-closed-large@2x.png │ │ └── window-open-large@2x.png │ │ ├── index.d.ts │ │ ├── modal-close.svg │ │ ├── no-video.svg │ │ └── spinner-animated.svg ├── strings │ └── index.ts ├── style │ ├── ThemeProvider.tsx │ ├── font.css │ ├── fonts │ │ ├── SFUIDisplay-Black.woff │ │ ├── SFUIDisplay-Black.woff2 │ │ ├── SFUIDisplay-Bold.woff │ │ ├── SFUIDisplay-Bold.woff2 │ │ ├── SFUIDisplay-Heavy.woff │ │ ├── SFUIDisplay-Heavy.woff2 │ │ ├── SFUIDisplay-Light.woff │ │ ├── SFUIDisplay-Light.woff2 │ │ ├── SFUIDisplay-Medium.woff │ │ ├── SFUIDisplay-Medium.woff2 │ │ ├── SFUIDisplay-Regular.woff │ │ ├── SFUIDisplay-Regular.woff2 │ │ ├── SFUIDisplay-Semibold.woff │ │ ├── SFUIDisplay-Semibold.woff2 │ │ ├── SFUIDisplay-Thin.woff │ │ ├── SFUIDisplay-Thin.woff2 │ │ ├── SFUIDisplay-Ultralight.woff │ │ ├── SFUIDisplay-Ultralight.woff2 │ │ ├── SFUIText-Bold.woff │ │ ├── SFUIText-Bold.woff2 │ │ ├── SFUIText-BoldItalic.woff │ │ ├── SFUIText-BoldItalic.woff2 │ │ ├── SFUIText-Heavy.woff │ │ ├── SFUIText-Heavy.woff2 │ │ ├── SFUIText-HeavyItalic.woff │ │ ├── SFUIText-HeavyItalic.woff2 │ │ ├── SFUIText-Light.woff │ │ ├── SFUIText-Light.woff2 │ │ ├── SFUIText-LightItalic.woff │ │ ├── SFUIText-LightItalic.woff2 │ │ ├── SFUIText-Medium.woff │ │ ├── SFUIText-Medium.woff2 │ │ ├── SFUIText-MediumItalic.woff │ │ ├── SFUIText-MediumItalic.woff2 │ │ ├── SFUIText-Regular.woff │ │ ├── SFUIText-Regular.woff2 │ │ ├── SFUIText-RegularItalic.woff │ │ ├── SFUIText-RegularItalic.woff2 │ │ ├── SFUIText-Semibold.woff │ │ ├── SFUIText-Semibold.woff2 │ │ ├── SFUIText-SemiboldItalic.woff │ │ ├── SFUIText-SemiboldItalic.woff2 │ │ ├── SFUIText-Ultralight.woff │ │ ├── SFUIText-Ultralight.woff2 │ │ ├── SFUIText-UltralightItalic.woff │ │ └── SFUIText-UltralightItalic.woff2 │ └── theme.ts └── types │ ├── index.ts │ └── types.ts ├── styleguide ├── Provider.js ├── images │ ├── camera_example.jpeg │ ├── heart.svg │ └── index.d.ts ├── styleguide.config.js └── webpack.config.js ├── tsconfig.json ├── webpack.config.base.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "@emotion", 4 | "@babel/plugin-transform-runtime", 5 | ["@babel/plugin-proposal-decorators", { "legacy": true }] 6 | ], 7 | "presets": [ 8 | "@babel/preset-env", 9 | "@babel/preset-react", 10 | "@babel/preset-typescript" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true 5 | }, 6 | "extends": [ 7 | "eslint:recommended", 8 | "plugin:react/recommended", 9 | "plugin:react-hooks/recommended", 10 | "plugin:@typescript-eslint/recommended" 11 | ], 12 | "parser": "@typescript-eslint/parser", 13 | "parserOptions": { 14 | "ecmaFeatures": { 15 | "jsx": true 16 | }, 17 | "ecmaVersion": 12, 18 | "sourceType": "module", 19 | "project": ["./tsconfig.json"] 20 | }, 21 | "plugins": [ 22 | "@typescript-eslint", 23 | "react-hooks" 24 | ], 25 | "rules": { 26 | "comma-dangle": ["error", "always-multiline"], 27 | "semi": ["error", "always"], 28 | "global-require": [0], 29 | "react/prop-types": "off", 30 | "react/display-name": "off", 31 | "quotes": [2, "single"], 32 | "@typescript-eslint/ban-types": ["error", 33 | { 34 | "extendDefaults": true, 35 | "types": { 36 | "{}": false 37 | } 38 | } 39 | ] 40 | }, 41 | "settings": { 42 | "react": { 43 | "version": "detect" 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | dist 4 | dist_doc 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.enabled": false 3 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HomeKit React Components 2 | 3 | List of React Component mimicating HomeKit components from the Home application (iOS, MacOS). 4 | 5 | 6 | ## Installation 7 | 8 | Install the package 9 | 10 | ``` 11 | npm install --save homekit-react-components 12 | ``` 13 | 14 | Install peer-dependencies if you don't already have them. 15 | 16 | ``` 17 | npm install --save react react-dom 18 | ``` 19 | 20 | 21 | 22 | 23 | 24 | ## Usage 25 | 26 | 1. Wrap your app with the theme provider. For now, no default theme are provided so you will need to inject the theme yourself. 27 | 28 | ```js 29 | import { ThemeProvider } from 'homekit-react-components'; 30 | 31 | function App() { 32 | return ( 33 | 34 | 35 | 36 | ); 37 | } 38 | ``` 39 | 40 | 2. Use any components in your code 🤗 41 | 42 | ```js 43 | const [ on, setOn ] = useState(true); 44 | 45 | setOn(prevState => !prevState)} 49 | /> 50 | ``` 51 | 52 | 53 | ## Documentation 54 | 55 | https://william57m.github.io/homekit-react-components/ 56 | 57 | 58 | ## Roadmap 59 | 60 | Here is a non exhaustive list of the next components to be developed: 61 | - Fan Card 62 | - Media Player Card 63 | - State component 64 | - Alarm card 65 | - Title, section component and different HomeKit layout 66 | - Support for light/dark mode 67 | 68 | Look at the [wiki](https://github.com/william57m/homekit-react-components/wiki/Improvements) for coming improvements. 69 | 70 | ## Contribution 71 | 72 | 🚧 TO BE COMPLETED 🚧 73 | 74 | ### homeassistant-dashboard 75 | 76 | > The below guide assumes you are developing for use with https://github.com/william57m/homeassistant-dashboard 77 | 78 | - Run `npm i --save homekit-react-components` to your [homeassistant-dashboard](https://github.com/william57m/homeassistant-dashboard) project 79 | - In this cloned repo, run `npm link` 80 | 81 | In your `homeassistant-dashboard` project, do the following: 82 | 83 | - Add the below into the module.exports of your `webpack.config.js` file: 84 | 85 | ``` 86 | resolve: { 87 | alias: { 88 | react: path.resolve('./node_modules/react'), 89 | '@emotion/react': path.resolve('./node_modules/@emotion/react'), 90 | }, 91 | }, 92 | ``` 93 | 94 | - Run `npm link homekit-react-components` 95 | - Run `npm run start` to start the dev server 96 | 97 | Any changes you make to `homekit-react-components` will be hot loaded via your `homeassistant-dashboard` project 98 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "homekit-react-components", 3 | "version": "1.0.0", 4 | "description": "HomeKit components for React", 5 | "main": "dist/index.js", 6 | "module": "dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "scripts": { 9 | "build": "run-s clean build:tsc build:webpack", 10 | "build:tsc": "tsc", 11 | "build:webpack": "webpack", 12 | "clean": "rm -rf dist", 13 | "doc": "styleguidist server --config styleguide/styleguide.config.js", 14 | "doc:build": "styleguidist build --config styleguide/styleguide.config.js", 15 | "doc:deploy": "gh-pages -d dist_doc", 16 | "lint": "eslint src/index.ts", 17 | "test": "echo \"Error: no test specified\" && exit 1" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/william57m/homekit-react-components.git" 22 | }, 23 | "author": "william57m", 24 | "license": "ISC", 25 | "bugs": { 26 | "url": "https://github.com/william57m/homekit-react-components/issues" 27 | }, 28 | "homepage": "https://github.com/william57m/homekit-react-components#readme", 29 | "devDependencies": { 30 | "@babel/core": "^7.16.5", 31 | "@babel/plugin-proposal-decorators": "^7.16.0", 32 | "@babel/plugin-transform-runtime": "^7.16.5", 33 | "@babel/preset-env": "^7.16.5", 34 | "@babel/preset-react": "^7.16.5", 35 | "@babel/preset-typescript": "^7.16.0", 36 | "@emotion/babel-plugin": "^11.7.1", 37 | "@emotion/react": "^11.7.1", 38 | "@emotion/styled": "^11.6.0", 39 | "@svgr/webpack": "^5.5.0", 40 | "@types/react": "^17.0.34", 41 | "@types/react-modal": "^3.13.1", 42 | "@typescript-eslint/eslint-plugin": "^5.3.1", 43 | "@typescript-eslint/parser": "^5.3.1", 44 | "babel-loader": "^8.2.3", 45 | "css-loader": "^5.0.2", 46 | "eslint": "^8.2.0", 47 | "eslint-plugin-react": "^7.27.0", 48 | "eslint-plugin-react-hooks": "^4.3.0", 49 | "file-loader": "^6.2.0", 50 | "gh-pages": "^3.2.3", 51 | "immer": ">=9.0.6", 52 | "npm-run-all": "^4.1.5", 53 | "nth-check": ">=2.0.1", 54 | "react": "^17.0.2", 55 | "react-docgen-typescript": "^2.1.1", 56 | "react-dom": "^17.0.2", 57 | "react-styleguidist": "^11.1.7", 58 | "style-loader": "^3.3.1", 59 | "typescript": "^4.4.4", 60 | "url-loader": "^4.1.1", 61 | "webpack": "^5.64.0", 62 | "webpack-cli": "^4.9.1", 63 | "webpack-merge": "^5.8.0", 64 | "webpack-node-externals": "^3.0.0" 65 | }, 66 | "peerDependencies": { 67 | "react": "^17.0.1", 68 | "react-dom": "^17.0.1" 69 | }, 70 | "dependencies": { 71 | "@babel/runtime": "^7.16.5", 72 | "@emotion/react": "^11.1.5", 73 | "@emotion/styled": "^11.1.5", 74 | "@fseehawer/react-circular-slider": "^2.3.9", 75 | "react-mobile-picker": "^0.1.12", 76 | "react-modal": "^3.14.4" 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/components/accessories/BinarySensorCard/BinarySensorCard.md: -------------------------------------------------------------------------------- 1 | Try changing the boolean `isActive` to `true` and notice the difference. You can also try to change the type. 2 | 3 | ```tsx 4 | import { BinarySensorType } from './BinarySensorCard'; 5 | 6 | 11 | ``` 12 | -------------------------------------------------------------------------------- /src/components/accessories/BinarySensorCard/BinarySensorCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, ReactNode } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | import { BinarySensorType } from '../../../types'; 5 | import { useBinarySensorIcon, useBinarySensorLabel } from '../../common/hooks'; 6 | import { AccessoryCard, AccessoryCardStatus } from '../../common/cards/AccessoryCard'; 7 | 8 | export { BinarySensorType }; 9 | 10 | 11 | const SensorCard = styled(AccessoryCard)` 12 | ${AccessoryCardStatus} { 13 | color: ${ 14 | props => props.isActive ? 15 | props.theme.sensorCard.state.colorActive : 16 | props.theme.sensorCard.state.colorInactive 17 | }; 18 | } 19 | `; 20 | 21 | interface BinarySensorCardProps { 22 | /** State of the binary sensor */ 23 | readonly isActive: boolean; 24 | /** Name of the binary sensor */ 25 | readonly name: string; 26 | /** Type of the sensor */ 27 | readonly type: BinarySensorType; 28 | /** Custom icon for active state */ 29 | readonly iconActive?: ReactNode; 30 | /** Custom icon for inactive state */ 31 | readonly iconInactive?: ReactNode; 32 | /** Custom label for active state */ 33 | readonly labelActive?: string; 34 | /** Custom label for inactive state */ 35 | readonly labelInactive?: string; 36 | } 37 | 38 | export const BinarySensorCard: FC = ({ 39 | isActive, 40 | name, 41 | type, 42 | iconActive, 43 | iconInactive, 44 | labelActive = 'Triggered', 45 | labelInactive = 'No motion', 46 | }) => { 47 | const { 48 | labelActive: binarySensorLabelActive, 49 | labelInactive: binarySensorLabelInactive, 50 | } = useBinarySensorLabel(type, labelActive, labelInactive); 51 | 52 | const { 53 | iconActive: binarySensorIconActive, 54 | iconInactive: binarySensorIconInactive, 55 | } = useBinarySensorIcon(type, iconActive, iconInactive); 56 | 57 | const stateLabel = isActive ? binarySensorLabelActive : binarySensorLabelInactive; 58 | 59 | return ( 60 | 67 | ); 68 | }; 69 | -------------------------------------------------------------------------------- /src/components/accessories/BinarySensorCard/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BinarySensorCard'; 2 | -------------------------------------------------------------------------------- /src/components/accessories/CameraCard/CameraCard.md: -------------------------------------------------------------------------------- 1 | Camera with valid stream 2 | 3 | ```tsx 4 | 8 | ``` 9 | 10 | Camera with broken stream 11 | 12 | ```tsx 13 | 17 | ``` 18 | -------------------------------------------------------------------------------- /src/components/accessories/CameraCard/CameraCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | import { CardContainer, CardTitle } from '../../common/cards'; 5 | import { useLoadImage } from '../../common/hooks'; 6 | import { LoadingPlaceholder } from './CameraCardPlaceholderLoading'; 7 | import { OfflinePlaceholder } from './CameraCardPlaceholderOffline'; 8 | 9 | 10 | const CameraCardContainer = styled(CardContainer)` 11 | position: relative; 12 | display: flex; 13 | flex-direction: column; 14 | width: ${props => props.theme.cameraCard.width}; 15 | height: ${props => props.theme.cameraCard.height}; 16 | background: black; 17 | `; 18 | 19 | const CameraCardContent = styled.div` 20 | flex-grow: 1; 21 | `; 22 | 23 | const CameraImage = styled.img` 24 | width: 100%; 25 | `; 26 | 27 | interface CameraCardProps { 28 | /** Name of the camera */ 29 | readonly name: string; 30 | /** Image URL for the camera preview */ 31 | readonly previewImageSrc: string; 32 | } 33 | 34 | export const CameraCard: FC = (props) => { 35 | const { isLoading, isLoaded } = useLoadImage(props.previewImageSrc); 36 | 37 | return ( 38 | 39 | {props.name} 40 | 41 | {isLoading ? 42 | : 43 | (isLoaded ? 44 | : 45 | 46 | ) 47 | } 48 | 49 | 50 | ); 51 | }; 52 | -------------------------------------------------------------------------------- /src/components/accessories/CameraCard/CameraCardPlaceholderLoading.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | import { ReactComponent as SpinnerAnimatedIcon } from '../../../resources/icons/spinner-animated.svg'; 5 | 6 | 7 | export const EmptyContainer = styled.div` 8 | display: flex; 9 | flex-direction: column; 10 | align-items: center; 11 | justify-content: center; 12 | height: 100%; 13 | color: gray; 14 | font-weight: bold; 15 | background: black; 16 | `; 17 | 18 | export const IconContainer = styled.div` 19 | width: 40px; 20 | `; 21 | 22 | export const TextContainer = styled.div` 23 | font-size: 12px; 24 | `; 25 | 26 | export const LoadingPlaceholder: FC<{}> = () => { 27 | return ( 28 | 29 | 30 | 31 | 32 | 33 | ); 34 | }; 35 | -------------------------------------------------------------------------------- /src/components/accessories/CameraCard/CameraCardPlaceholderOffline.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from 'react'; 2 | 3 | import { ReactComponent as NoVideoIconSvg } from '../../../resources/icons/no-video.svg'; 4 | import { EmptyContainer, IconContainer, TextContainer } from './CameraCardPlaceholderLoading'; 5 | 6 | 7 | export const OfflinePlaceholder: FC<{}> = () => { 8 | return ( 9 | 10 | 11 | 12 | 13 | 14 | Camera offline 15 | 16 | 17 | ); 18 | }; 19 | -------------------------------------------------------------------------------- /src/components/accessories/CameraCard/index.ts: -------------------------------------------------------------------------------- 1 | export { CameraCard } from './CameraCard'; 2 | -------------------------------------------------------------------------------- /src/components/accessories/LightCard/LightCard.md: -------------------------------------------------------------------------------- 1 | #### Regular light 2 | 3 | Click and hold to display more options 4 | 5 | ```tsx 6 | const [ on, setOn ] = React.useState(true); 7 | 8 | setOn(prevState => !prevState)} 12 | /> 13 | ``` 14 | 15 | #### Dimmable light 16 | 17 | Click and hold to set the brightness 18 | 19 | ```tsx 20 | const [ on, setOn ] = React.useState(true); 21 | const [ brightness, setBrightness ] = React.useState(100); 22 | 23 | setOn(prevState => !prevState)} 27 | brightness={on ? brightness : 0} 28 | onBrightnessChange={(value) => { setBrightness(value); setOn(value != 0); }} 29 | capabilities={{ 30 | SUPPORT_BRIGHTNESS: true 31 | }} 32 | /> 33 | ``` 34 | -------------------------------------------------------------------------------- /src/components/accessories/LightCard/LightCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, ReactNode } from 'react'; 2 | 3 | import { LightIconSvg } from '../../icons'; 4 | import { AccessoryCard } from '../../common/cards/AccessoryCard'; 5 | import { useModalHelper } from '../../common/hooks'; 6 | import { Capabilities } from '../../../types'; 7 | import { LightCardModal } from './LightCardModal'; 8 | 9 | 10 | interface LightCardProps { 11 | /** Custom icon for active light */ 12 | readonly iconActive?: ReactNode; 13 | /** Custom icon for inactive light */ 14 | readonly iconInactive?: ReactNode; 15 | /** Action triggered on press */ 16 | readonly onToggle?: () => void; 17 | /** Action triggered when brightness change */ 18 | readonly onBrightnessChange?: (value: number) => void; 19 | /** State of the light */ 20 | readonly on: boolean; 21 | /** Name of the light */ 22 | readonly name: string; 23 | /** Brightness of the light */ 24 | readonly brightness?: number; 25 | /** Capabilities of the light (dimmable, color, ...) */ 26 | readonly capabilities?: Capabilities; 27 | } 28 | 29 | export const LightCard: FC = ({ 30 | capabilities = { 31 | SUPPORT_BRIGHTNESS: false, 32 | SUPPORT_COLOR: false, 33 | }, 34 | brightness, 35 | iconActive, 36 | iconInactive, 37 | name, 38 | on, 39 | onToggle, 40 | onBrightnessChange, 41 | }) => { 42 | const { showModal, openModal, closeModal } = useModalHelper(); 43 | 44 | const stateLabel = on ? 45 | brightness ? `${brightness}%` : 'On' : 46 | 'Off'; 47 | 48 | return ( 49 | 50 | } 52 | iconInactive={iconInactive ? iconInactive : } 53 | name={name} 54 | state={stateLabel} 55 | isActive={on} 56 | handlePress={onToggle} 57 | handleLongPress={openModal} 58 | /> 59 | 69 | 70 | ); 71 | }; 72 | -------------------------------------------------------------------------------- /src/components/accessories/LightCard/LightCardModal.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, useState } from 'react'; 2 | import Modal from 'react-modal'; 3 | 4 | import { LightIconSvg } from '../../icons'; 5 | import { ModalContainer, ModalContent, ModalHeader, ModalStyle } from '../../common/modals'; 6 | import { Slider, Switch } from '../../common'; 7 | import { Capabilities } from '../../../types'; 8 | 9 | // Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/) 10 | Modal.setAppElement('html'); 11 | 12 | 13 | interface LightCardModalProps { 14 | /** Brightness value */ 15 | readonly brightness?: number; 16 | /** Capabilities of the light */ 17 | readonly capabilities: Capabilities; 18 | /** Method to close the modal */ 19 | readonly close: () => void; 20 | /** Color of the light */ 21 | readonly color?: string; 22 | /** Name of the light */ 23 | readonly name: string; 24 | /** State of the light */ 25 | readonly on: boolean; 26 | /** Action triggered on toggle switch */ 27 | readonly onToggle?: () => void; 28 | /** Action triggered on brightness change */ 29 | readonly onBrightnessChange?: (value: number) => void; 30 | /** Action triggered on color change */ 31 | readonly onColorChange?: () => void; 32 | /** State of the modal */ 33 | readonly show: boolean; 34 | /** State label of the light */ 35 | readonly state: string; 36 | } 37 | 38 | export const LightCardModal: FC = (props) => { 39 | const [ color ] = useState('#F8CC46'); 40 | 41 | const stateLabel = props.capabilities.SUPPORT_BRIGHTNESS ? 42 | (props.brightness && props.brightness > 0 ? `${props.brightness}% Brightness` : props.state) : 43 | (props.state); 44 | 45 | function handleSliderChange(value: number) { 46 | if (props.onBrightnessChange) { 47 | props.onBrightnessChange(value); 48 | } 49 | } 50 | 51 | return ( 52 | 58 | 59 | 65 | } 66 | /> 67 | 68 | {props.capabilities.SUPPORT_BRIGHTNESS ? 69 | : 74 | props.onToggle && props.onToggle()} 77 | /> 78 | } 79 | {props.capabilities.SUPPORT_COLOR ? 80 |
81 | TODO: Implement color picker 82 |
: null 83 | } 84 |
85 |
86 |
87 | ); 88 | }; 89 | -------------------------------------------------------------------------------- /src/components/accessories/LightCard/index.ts: -------------------------------------------------------------------------------- 1 | export * from './LightCard'; 2 | -------------------------------------------------------------------------------- /src/components/accessories/SwitchCard/SwitchCard.md: -------------------------------------------------------------------------------- 1 | ```tsx 2 | import { SwitchType } from './SwitchCard' 3 | 4 | const [ on, setOn ] = React.useState(true); 5 | 6 | setOn(prevState => !prevState)} 11 | /> 12 | ``` 13 | -------------------------------------------------------------------------------- /src/components/accessories/SwitchCard/SwitchCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, ReactNode } from 'react'; 2 | 3 | import { SwitchType } from '../../../types'; 4 | import { AccessoryCard } from '../../common/cards/AccessoryCard'; 5 | import { useSwitchIcon, useSwitchLabel } from '../../common/hooks'; 6 | 7 | export { SwitchType }; 8 | 9 | 10 | interface SwitchCardProps { 11 | /** State of the switch */ 12 | readonly on: boolean; 13 | /** Type of the switch */ 14 | readonly type: SwitchType; 15 | /** Name of the switch */ 16 | readonly name: string; 17 | /** Action triggered on press */ 18 | readonly onToggle?: () => void; 19 | /** Custom icon for active state */ 20 | readonly iconActive?: ReactNode; 21 | /** Custom icon for inactive state */ 22 | readonly iconInactive?: ReactNode; 23 | /** Custom label for active state */ 24 | readonly labelActive?: string; 25 | /** Custom label for inactive state */ 26 | readonly labelInactive?: string; 27 | } 28 | 29 | export const SwitchCard: FC = ({ 30 | on, 31 | type, 32 | name, 33 | onToggle, 34 | iconActive, 35 | iconInactive, 36 | labelActive = 'On', 37 | labelInactive = 'Off', 38 | }) => { 39 | const { 40 | labelActive: switchLabelActive, 41 | labelInactive: switchLabelInactive, 42 | } = useSwitchLabel(type, labelActive, labelInactive); 43 | 44 | const { 45 | iconActive: switchIconActive, 46 | iconInactive: switchIconInactive, 47 | } = useSwitchIcon(type, iconActive, iconInactive); 48 | 49 | const stateLabel = on ? switchLabelActive : switchLabelInactive; 50 | 51 | return ( 52 | 60 | ); 61 | }; 62 | -------------------------------------------------------------------------------- /src/components/accessories/SwitchCard/index.ts: -------------------------------------------------------------------------------- 1 | export * from './SwitchCard'; 2 | -------------------------------------------------------------------------------- /src/components/accessories/ThermostatCard/ThermostatCard.md: -------------------------------------------------------------------------------- 1 | Click or hold to display more options 2 | 3 | 🚧 WIP 4 | 5 | ```tsx 6 | const [temperature, setTemperature] = React.useState(22.0); 7 | const [mode, setMode] = React.useState('Heat'); 8 | 9 | setMode(value)} 13 | onToggle={() => setIsActive(!isActive)} 14 | currentTemperature={20} 15 | targetTemperature={temperature} 16 | onTemperatureChange={(value) => setTemperature(value)} 17 | /> 18 | ``` 19 | 20 | -------------------------------------------------------------------------------- /src/components/accessories/ThermostatCard/ThermostatCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from 'react'; 2 | 3 | import { AccessoryCard } from '../../common/cards/AccessoryCard'; 4 | import { useModalHelper } from '../../common/hooks'; 5 | import { TemperatureIcon } from '../../common/TemperatureIcon'; 6 | import { ThermostatCardModal } from './ThermostatCardModal'; 7 | 8 | 9 | interface ThermostatCardProps { 10 | /** Current mode */ 11 | readonly currentMode: string; 12 | /** Current temperature */ 13 | readonly currentTemperature: number; 14 | /** Modes available */ 15 | readonly modes?: string[]; 16 | /** Name of the thermostat */ 17 | readonly name: string; 18 | /** Action triggered when mode change */ 19 | readonly onModeChange?: (value: string) => void; 20 | /** Action triggered when temperature change */ 21 | readonly onTemperatureChange?: (value: number) => void; 22 | /** Target temperature */ 23 | readonly targetTemperature: number; 24 | /** Temperature max */ 25 | readonly tempMax?: number; 26 | /** Temperature min */ 27 | readonly tempMin?: number; 28 | } 29 | 30 | export const ThermostatCard: FC = ({ 31 | currentMode, 32 | currentTemperature, 33 | modes = ['Off', 'Heat', 'Auto'], 34 | name, 35 | onModeChange, 36 | onTemperatureChange, 37 | targetTemperature, 38 | tempMax = 30, 39 | tempMin = 6, 40 | }) => { 41 | const { showModal, openModal, closeModal } = useModalHelper(); 42 | 43 | const stateLabel = currentMode !== 'Off' ? 44 | `Heat to ${targetTemperature.toFixed(1)}°` : 45 | 'Off'; 46 | 47 | return ( 48 | 49 | 52 | } 53 | iconInactive={ 54 | 55 | } 56 | name={name} 57 | state={stateLabel} 58 | isActive={currentMode !== 'Off'} 59 | handlePress={openModal} 60 | handleLongPress={openModal} 61 | /> 62 | 75 | 76 | ); 77 | }; 78 | -------------------------------------------------------------------------------- /src/components/accessories/ThermostatCard/ThermostatCardModal.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from 'react'; 2 | import Modal from 'react-modal'; 3 | import styled from '@emotion/styled'; 4 | import CircularSlider from '@fseehawer/react-circular-slider'; 5 | import Picker from 'react-mobile-picker'; 6 | 7 | import { ModalContainer, ModalContent, ModalHeader, ModalStyle } from '../../common/modals'; 8 | import { TemperatureIcon } from '../../common/TemperatureIcon'; 9 | 10 | // Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/) 11 | Modal.setAppElement('html'); 12 | 13 | 14 | const CircularSliderContainer = styled.div` 15 | position: relative; 16 | margin-bottom: 40px; 17 | `; 18 | 19 | const LabelContainer = styled.div` 20 | position: absolute; 21 | top: 85px; 22 | left: 70px; 23 | `; 24 | 25 | const LabelTitle = styled.div` 26 | color: #F29F41; 27 | font-size: 14px; 28 | font-weight: 600; 29 | `; 30 | 31 | const LabelTemperature = styled.div` 32 | font-size: 48px; 33 | font-weight: bold; 34 | `; 35 | 36 | interface ThermostatCardModalProps { 37 | /** Method to close the modal */ 38 | readonly close: () => void; 39 | /** Current mode */ 40 | readonly currentMode?: string; 41 | /** Current temperature */ 42 | readonly currentTemperature: number; 43 | /** List of modes available */ 44 | readonly modes?: string[]; 45 | /** Name of the thermostat */ 46 | readonly name: string; 47 | /** Target temperature */ 48 | readonly targetTemperature: number; 49 | /** Action triggered on temperature change */ 50 | readonly onTemperatureChange?: (value: number) => void; 51 | /** Action triggered on mode change */ 52 | readonly onModeChange?: (value: string) => void; 53 | /** State of the modal */ 54 | readonly show: boolean; 55 | /** State label of the thermostat */ 56 | readonly state: string; 57 | /** Temperature max */ 58 | readonly tempMax: number; 59 | /** Temperature min */ 60 | readonly tempMin: number; 61 | } 62 | 63 | export const ThermostatCardModal: FC = ({ 64 | close, 65 | currentMode, 66 | currentTemperature, 67 | modes, 68 | name, 69 | targetTemperature, 70 | onTemperatureChange, 71 | onModeChange, 72 | show, 73 | state, 74 | tempMax, 75 | tempMin, 76 | }) => { 77 | const on = currentMode !== 'Off'; 78 | const stateLabel = on ? `Heat to ${targetTemperature.toFixed(1)}°` : 'Off'; 79 | 80 | function handleSliderChange(value: number) { 81 | if (onTemperatureChange) { 82 | onTemperatureChange(value); 83 | } 84 | } 85 | 86 | function handleModeChange(key: string, value: string) { 87 | if (onModeChange) { 88 | onModeChange(value); 89 | } 90 | } 91 | 92 | 93 | return ( 94 | 100 | 101 | 107 | } 108 | /> 109 | 110 | 111 | 129 | 130 | {on ? 'HEATING TO' : 'NOW'} 131 | {on ? targetTemperature.toFixed(1) : currentTemperature.toFixed(1)}° 132 | 133 | 134 | 143 | 144 | 145 | 146 | ); 147 | }; 148 | -------------------------------------------------------------------------------- /src/components/accessories/ThermostatCard/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ThermostatCard'; 2 | -------------------------------------------------------------------------------- /src/components/accessories/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BinarySensorCard'; 2 | export * from './CameraCard'; 3 | export * from './LightCard'; 4 | export * from './SwitchCard'; 5 | export * from './ThermostatCard'; 6 | -------------------------------------------------------------------------------- /src/components/common/Slider.tsx: -------------------------------------------------------------------------------- 1 | import React, { ChangeEvent, FC, useState } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | 5 | const SliderContainer = styled.div` 6 | height: 280px; 7 | `; 8 | 9 | const CustomSlider = styled.input` 10 | -webkit-appearance: none; 11 | /* Width */ 12 | height: 90px; 13 | /* Height */ 14 | width: 260px; 15 | margin-top: 80px; 16 | outline: none; 17 | border-radius: 20px; 18 | background: ${props => props.theme.colors.light2}; 19 | overflow: hidden; 20 | transform: rotate(-90deg); 21 | 22 | &::-webkit-slider-thumb { 23 | -webkit-appearance: none; 24 | width: 20px; 25 | height: 40px; 26 | border-radius: 20px; 27 | border: 8px solid ${props => props.color}; 28 | box-shadow: -100vw 0 0 100vw ${props => props.color}; 29 | } 30 | `; 31 | 32 | let timeout: NodeJS.Timeout; 33 | 34 | interface SliderProps { 35 | /** Color of the slider */ 36 | readonly color: string; 37 | /** Action triggered on slider change */ 38 | readonly onChange: (value: number) => void; 39 | /** Value of the slider */ 40 | readonly value: number; 41 | } 42 | 43 | export const Slider: FC = (props) => { 44 | const [value, setValue] = useState(props.value); 45 | 46 | function handleChange(event: ChangeEvent) { 47 | const value = parseInt(event.target.value); 48 | setValue(value); 49 | timeout && clearTimeout(timeout); 50 | timeout = setTimeout(() => { 51 | props.onChange(value); 52 | }, 200); 53 | } 54 | 55 | return ( 56 | 57 | 65 | 66 | ); 67 | }; 68 | -------------------------------------------------------------------------------- /src/components/common/Switch.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | import { WithActiveProps } from './types'; 5 | 6 | 7 | const Slider = styled.div` 8 | -webkit-transition: .4s; 9 | transition: .4s; 10 | 11 | &:before { 12 | position: absolute; 13 | content: ""; 14 | margin: 5px 0 0 5px; 15 | height: 125px; 16 | width: 80px; 17 | left: 0px; 18 | top: 125px; 19 | -webkit-transition: .4s; 20 | transition: .4s; 21 | border-radius: 18px; 22 | background-color: ${props => props.isActive ? props.theme.colors.lightActive : props.theme.colors.lightGray}; 23 | } 24 | `; 25 | 26 | const SwitchContainer = styled.label` 27 | background: ${props => props.theme.colors.light2}; 28 | height: 260px; 29 | width: 90px; 30 | border-radius: 20px; 31 | cursor: pointer; 32 | position: relative; 33 | 34 | input { 35 | opacity: 0; 36 | width: 0; 37 | height: 0; 38 | } 39 | 40 | input:checked + ${Slider}:before { 41 | -webkit-transform: translateY(-125px); 42 | -ms-transform: translateY(-125px); 43 | transform: translateY(-125px); 44 | } 45 | `; 46 | 47 | interface SwitchProps { 48 | /** State of the switch */ 49 | readonly isActive: boolean; 50 | /** Action triggered on toggle */ 51 | readonly onToggle: () => void; 52 | } 53 | 54 | export const Switch: FC = (props) => { 55 | return ( 56 | 57 | 58 | 59 | 60 | ); 61 | }; 62 | -------------------------------------------------------------------------------- /src/components/common/TemperatureIcon.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | 5 | const TemperatureLogoContainer = styled.div` 6 | display: flex; 7 | align-items: center; 8 | width: 1.8rem; 9 | height: 1.8rem; 10 | background-color: ${props => props.theme.colors.green}; 11 | border-radius: 45px; 12 | `; 13 | 14 | const TemperatureText = styled.div` 15 | text-align: center; 16 | width: 100%; 17 | font-size: 0.5rem; 18 | font-weight: bold; 19 | color: ${props => props.theme.colors.light1}; 20 | `; 21 | 22 | interface TemperatureIconProps { 23 | /** Temperature value */ 24 | readonly temperature: number; 25 | } 26 | 27 | export const TemperatureIcon: FC = (props) => { 28 | return ( 29 | 30 | {props.temperature.toFixed(1)}° 31 | 32 | ); 33 | }; 34 | -------------------------------------------------------------------------------- /src/components/common/cards/AccessoryCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, ReactNode } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | import { ActionableCardContainer, CardIcon, CardName, CardState } from './Card'; 5 | 6 | 7 | export const AccessoryCardContainer = styled(ActionableCardContainer)` 8 | display: grid; 9 | padding: 10px; 10 | grid-template-areas: 11 | "icon info" 12 | "name name" 13 | "status status" 14 | ; 15 | grid-template-columns: repeat(2, 1fr); 16 | grid-template-rows: 1fr 2fr 1fr; 17 | max-height: ${props => props.theme.card.size}; 18 | align-items: start; 19 | overflow: hidden; 20 | width: ${props => props.theme.card.size}; 21 | height: ${props => props.theme.card.size}; 22 | cursor: pointer; 23 | font-family: 'SF UI Display'; 24 | `; 25 | 26 | export const AccessoryCardName = styled(CardName)` 27 | justify-self: start; 28 | align-self: flex-end; 29 | grid-area: name; 30 | display: -webkit-box; 31 | -webkit-line-clamp: 2; 32 | -webkit-box-orient: vertical; 33 | overflow: hidden; 34 | margin-bottom: 0.2rem; 35 | text-overflow: ellipsis; 36 | `; 37 | 38 | export const AccessoryCardStatus = styled(CardState)` 39 | justify-self: start; 40 | align-self: center; 41 | grid-area: status; 42 | `; 43 | 44 | export const AccessoryCardIcon = styled(CardIcon)` 45 | justify-self: start; 46 | grid-area: icon; 47 | width: 1.8rem; 48 | margin-bottom: 0.5rem; 49 | `; 50 | 51 | let buttonPressTimer: NodeJS.Timeout; 52 | 53 | export interface AccessoryCardProps { 54 | /** Children */ 55 | readonly children?: ReactNode; 56 | /** Custom className */ 57 | readonly className?: string; 58 | /** Action triggered on long press */ 59 | readonly handleLongPress?: () => void; 60 | /** Action triggered on press */ 61 | readonly handlePress?: () => void; 62 | /** Icon for active state */ 63 | readonly iconActive?: ReactNode; 64 | /** Icon for inactive state */ 65 | readonly iconInactive?: ReactNode; 66 | /** State of the card */ 67 | readonly isActive: boolean; 68 | /** Name label of the card */ 69 | readonly name: string; 70 | /** State label of the card */ 71 | readonly state: string; 72 | } 73 | 74 | export const AccessoryCard: FC = (props) => { 75 | 76 | function handlePress() { 77 | if (props.handlePress) { 78 | props.handlePress(); 79 | } 80 | } 81 | 82 | function handleButtonPress () { 83 | if (props.handleLongPress) { 84 | buttonPressTimer = setTimeout(() => props.handleLongPress && props.handleLongPress(), 1000); 85 | } 86 | } 87 | 88 | function handleButtonRelease () { 89 | clearTimeout(buttonPressTimer); 90 | } 91 | 92 | const icon = props.isActive ? props.iconActive : props.iconInactive; 93 | 94 | return ( 95 | 105 | {icon} 106 | {props.name} 107 | {props.state} 108 | {props.children} 109 | 110 | ); 111 | }; 112 | -------------------------------------------------------------------------------- /src/components/common/cards/Card.tsx: -------------------------------------------------------------------------------- 1 | import styled from '@emotion/styled'; 2 | import { WithActiveProps } from '../types'; 3 | 4 | 5 | export const CardContainer = styled.div` 6 | border-radius: ${props => props.theme.card.borderRadius}; 7 | box-sizing: border-box; 8 | overflow: hidden; 9 | font-family: 'SF UI Display'; 10 | user-select: none; 11 | `; 12 | 13 | export const ActionableCardContainer = styled(CardContainer)` 14 | background-color: ${props => props.isActive ? props.theme.card.background.colorActive : props.theme.card.background.colorInactive}; 15 | opacity: ${props => props.isActive ? '100%' : (props.isActive === false ? '70%' : '100%')}; 16 | cursor: pointer; 17 | &:active { 18 | transform: scale(0.9); 19 | } 20 | `; 21 | 22 | export const CardName = styled.div` 23 | font-size: ${props => props.theme.card.name.size}; 24 | font-weight: ${props => props.theme.card.name.weight}; 25 | color: ${props => props.isActive ? props.theme.card.name.colorActive : props.theme.card.name.colorInactive}; 26 | `; 27 | 28 | export const CardState = styled.div` 29 | font-size: ${props => props.theme.card.state.size}; 30 | font-weight: ${props => props.theme.card.state.weight}; 31 | color: ${props => props.isActive ? props.theme.card.state.colorActive : props.theme.card.state.colorInactive}; 32 | `; 33 | 34 | export const CardIcon = styled.div` 35 | filter: ${props => props.isActive ? 'grayscale(0%)' : 'grayscale(100%)'} ; 36 | 37 | svg, img { 38 | height: 28px; 39 | max-height: 28px; 40 | } 41 | `; 42 | 43 | export const CardTitle = styled.div` 44 | width: 100%; 45 | height: 30px; 46 | line-height: 30px; 47 | background-color: ${props => props.theme.card.background.colorActive}; 48 | color: ${props => props.theme.colors.textDark}; 49 | padding-left: 10px; 50 | box-sizing: border-box; 51 | font-size: ${props => props.theme.card.name.size}; 52 | font-weight: ${props => props.theme.card.name.weight}; 53 | `; 54 | -------------------------------------------------------------------------------- /src/components/common/cards/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Card'; 2 | export * from './AccessoryCard'; 3 | -------------------------------------------------------------------------------- /src/components/common/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export * from './useBinarySensorIcon'; 2 | export * from './useBinarySensorLabel'; 3 | export * from './useLoadImage'; 4 | export * from './useModalHelper'; 5 | export * from './useSwitchIcon'; 6 | export * from './useSwitchLabel'; 7 | -------------------------------------------------------------------------------- /src/components/common/hooks/useBinarySensorIcon.ts: -------------------------------------------------------------------------------- 1 | import { ReactNode } from 'react'; 2 | import { getBinarySensorIcon } from '../../icons'; 3 | import { BinarySensorType } from '../../../types'; 4 | 5 | 6 | type UseBinarySensorIconProps = (type: BinarySensorType, iconActive: ReactNode, iconInactive: ReactNode) 7 | => { iconActive: ReactNode, iconInactive: ReactNode }; 8 | 9 | export const useBinarySensorIcon: UseBinarySensorIconProps = (type, iconActive, iconInactive) => { 10 | if (type === BinarySensorType.CUSTOM) { 11 | return { iconActive, iconInactive }; 12 | } 13 | return getBinarySensorIcon(type); 14 | }; 15 | -------------------------------------------------------------------------------- /src/components/common/hooks/useBinarySensorLabel.ts: -------------------------------------------------------------------------------- 1 | import { getBinarySensorLabel } from '../../../strings'; 2 | import { BinarySensorType } from '../../../types'; 3 | 4 | 5 | type UseBinarySensorLabelProps = (type: BinarySensorType, labelActive: string, labelInactive: string) 6 | => { labelActive: string, labelInactive: string }; 7 | 8 | export const useBinarySensorLabel: UseBinarySensorLabelProps = (type, labelActive, labelInactive) => { 9 | if (type === BinarySensorType.CUSTOM) { 10 | return { labelActive, labelInactive }; 11 | } 12 | return getBinarySensorLabel(type); 13 | }; 14 | -------------------------------------------------------------------------------- /src/components/common/hooks/useLoadImage.ts: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react'; 2 | 3 | 4 | type UseLoadImageProps = (url: string) => { isLoading: boolean, isLoaded: boolean }; 5 | 6 | export const useLoadImage: UseLoadImageProps = (url: string) => { 7 | const [isLoading, setIsLoading] = useState(true); 8 | const [isLoaded, setIsLoaded] = useState(false); 9 | 10 | useEffect(() => { 11 | try { 12 | fetch(url).then(r => { 13 | if(r.status == 200) { 14 | setIsLoaded(true); 15 | } 16 | setIsLoading(false); 17 | }); 18 | } catch (e) { 19 | setIsLoaded(false); 20 | setIsLoading(false); 21 | } 22 | }, [url]); 23 | 24 | return { isLoading, isLoaded}; 25 | }; 26 | -------------------------------------------------------------------------------- /src/components/common/hooks/useModalHelper.ts: -------------------------------------------------------------------------------- 1 | import { useState } from 'react'; 2 | 3 | 4 | type UseModalHelperProps = () => { showModal: boolean, openModal: () => void, closeModal: () => void }; 5 | 6 | export const useModalHelper: UseModalHelperProps = () => { 7 | const [showModal, setShowModal] = useState(false); 8 | 9 | function openModal() { 10 | setShowModal(true); 11 | } 12 | function closeModal() { 13 | setShowModal(false); 14 | } 15 | 16 | return { showModal, openModal, closeModal }; 17 | }; 18 | -------------------------------------------------------------------------------- /src/components/common/hooks/useSwitchIcon.ts: -------------------------------------------------------------------------------- 1 | import { ReactNode } from 'react'; 2 | import { getSwitchIcon } from '../../icons'; 3 | import { SwitchType } from '../../../types'; 4 | 5 | 6 | type UseSwitchIconProps = (type: SwitchType, iconActive: ReactNode, iconInactive: ReactNode) 7 | => { iconActive: ReactNode, iconInactive: ReactNode }; 8 | 9 | export const useSwitchIcon: UseSwitchIconProps = (type, iconActive, iconInactive) => { 10 | if (type === SwitchType.CUSTOM) { 11 | return { iconActive, iconInactive }; 12 | } 13 | return getSwitchIcon(type); 14 | }; 15 | -------------------------------------------------------------------------------- /src/components/common/hooks/useSwitchLabel.ts: -------------------------------------------------------------------------------- 1 | import { getSwitchLabel } from '../../../strings'; 2 | import { SwitchType } from '../../../types'; 3 | 4 | 5 | type UseSwitchLabelProps = (type: SwitchType, labelActive: string, labelInactive: string) 6 | => { labelActive: string, labelInactive: string }; 7 | 8 | export const useSwitchLabel: UseSwitchLabelProps = (type, labelActive, labelInactive) => { 9 | if (type === SwitchType.CUSTOM) { 10 | return { labelActive, labelInactive }; 11 | } 12 | return getSwitchLabel(type); 13 | }; 14 | -------------------------------------------------------------------------------- /src/components/common/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Slider'; 2 | export * from './Switch'; 3 | -------------------------------------------------------------------------------- /src/components/common/modals/Modal.tsx: -------------------------------------------------------------------------------- 1 | import styled from '@emotion/styled'; 2 | 3 | 4 | export const ModalContainer = styled.div` 5 | background-color: ${props => props.theme.colors.light1}; 6 | width: 300px; 7 | border-radius: 10px; 8 | `; 9 | 10 | export const ModalContent = styled.div` 11 | padding: 10px; 12 | text-align: center; 13 | display: flex; 14 | padding: 60px; 15 | align-items: center; 16 | justify-content: center; 17 | flex-direction: column; 18 | `; 19 | 20 | export const ModalStyle = { 21 | overlay: { 22 | // position: 'fixed', 23 | padding: 0, 24 | backgroundColor: '#404040CC', 25 | }, 26 | content: { 27 | background: 'transparent', 28 | border: 'none', 29 | padding: 0, 30 | top: '50px', 31 | right: 'initial', 32 | bottom: 'initial', 33 | left: 'calc(50% - 150px)', 34 | }, 35 | }; 36 | -------------------------------------------------------------------------------- /src/components/common/modals/ModalHeader.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, ReactNode } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | import CloseIconSvg from '../../../resources/icons/modal-close.svg'; 5 | 6 | 7 | const ModalHeaderContainer = styled.div` 8 | height: 24px; 9 | padding: 10px; 10 | position: relative; 11 | display: flex; 12 | `; 13 | 14 | const IconContainer = styled.div` 15 | margin-right: 10px; 16 | svg, img { 17 | height: 24px; 18 | } 19 | `; 20 | 21 | const TitleContainer = styled.div` 22 | display: flex; 23 | flex-direction: column; 24 | flex-grow: 1; 25 | `; 26 | 27 | const Title = styled.div` 28 | color: ${props => props.theme.modal.header.title.color}; 29 | font-size: ${props => props.theme.modal.header.title.size}; 30 | font-weight: ${props => props.theme.modal.header.title.weight}; 31 | `; 32 | 33 | const Subtitle = styled.div` 34 | color: ${props => props.theme.modal.header.subtitle.color}; 35 | font-size: ${props => props.theme.modal.header.subtitle.size}; 36 | font-weight: ${props => props.theme.modal.header.subtitle.weight}; 37 | `; 38 | 39 | const CloseIconContainer = styled.div` 40 | background: ${props => props.theme.colors.light2}; 41 | width: 24px; 42 | height: 24px; 43 | border-radius: 100%; 44 | text-align: center; 45 | cursor: pointer; 46 | img { 47 | height: 18px; 48 | margin-top: 3px; 49 | } 50 | `; 51 | 52 | interface ModalHeaderProps { 53 | /** Method to close the modal */ 54 | readonly close: () => void; 55 | /** Icon of the header */ 56 | readonly icon: ReactNode; 57 | /** Subtitle of the header */ 58 | readonly subtitle: string; 59 | /** Title of the header */ 60 | readonly title: string; 61 | } 62 | 63 | export const ModalHeader: FC = (props) => { 64 | return ( 65 | 66 | 67 | {props.icon} 68 | 69 | 70 | {props.title} 71 | {props.subtitle} 72 | 73 | 74 | 75 | 76 | 77 | ); 78 | }; 79 | -------------------------------------------------------------------------------- /src/components/common/modals/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Modal'; 2 | export * from './ModalHeader'; 3 | -------------------------------------------------------------------------------- /src/components/common/types.tsx: -------------------------------------------------------------------------------- 1 | export type WithActiveProps = { 2 | readonly isActive: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /src/components/icons/index.md: -------------------------------------------------------------------------------- 1 | ```jsx 2 | import { 3 | LightIconSvg, 4 | } from '.'; 5 | 6 |
7 |
Lights
8 | 9 |
10 | ``` -------------------------------------------------------------------------------- /src/components/icons/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { ReactNode } from 'react'; 2 | import { BinarySensorType, SwitchType} from '../../types'; 3 | 4 | 5 | /** 6 | * Sensors 7 | */ 8 | import ContactClosedSrc from '../../resources/icons/accessories/contact-closed-large@2x.png'; 9 | import ContactOpenSrc from '../../resources/icons/accessories/contact-open-large@2x.png'; 10 | 11 | import DoorClosedSrc from '../../resources/icons/accessories/door-closed-large@2x.png'; 12 | import DoorOpenSrc from '../../resources/icons/accessories/door-open-large@2x.png'; 13 | 14 | import LockSecuredSrc from '../../resources/icons/accessories/lock-secured-large@2x.png'; 15 | import LockUnsecuredSrc from '../../resources/icons/accessories/lock-unsecured-large@2x.png'; 16 | 17 | import MotionOffSrc from '../../resources/icons/accessories/motion-off-large@2x.png'; 18 | import MotionOnSrc from '../../resources/icons/accessories/motion-on-large@2x.png'; 19 | 20 | import WindowClosedSrc from '../../resources/icons/accessories/window-closed-large@2x.png'; 21 | import WindowOpenSrc from '../../resources/icons/accessories/window-open-large@2x.png'; 22 | 23 | /** 24 | * Switch 25 | */ 26 | import OutletOffSrc from '../../resources/icons/accessories/outlet-off-large@2x.png'; 27 | import OutletOnSrc from '../../resources/icons/accessories/outlet-on-large@2x.png'; 28 | 29 | import SwitchOffSrc from '../../resources/icons/accessories/switch-off-large@2x.png'; 30 | import SwitchOnSrc from '../../resources/icons/accessories/switch-on-large@2x.png'; 31 | 32 | /** 33 | * Light 34 | */ 35 | export { ReactComponent as LightIconSvg } from '../../resources/icons/accessories/light-bulb.svg'; 36 | 37 | 38 | type GetIconProps = (src: string) => ReactNode 39 | const getIcon: GetIconProps = (src: string) => ; 40 | 41 | type GetBinarySensorIconProps = (type: BinarySensorType) => { iconActive: ReactNode, iconInactive: ReactNode } 42 | export const getBinarySensorIcon: GetBinarySensorIconProps = (type) => { 43 | let iconActiveSrc = ''; 44 | let iconInactiveSrc = ''; 45 | 46 | switch(type) { 47 | case BinarySensorType.CONTACT: 48 | iconInactiveSrc = ContactClosedSrc; 49 | iconActiveSrc = ContactOpenSrc; 50 | break; 51 | case BinarySensorType.DOOR: 52 | iconInactiveSrc = DoorClosedSrc; 53 | iconActiveSrc = DoorOpenSrc; 54 | break; 55 | case BinarySensorType.LOCK: 56 | iconInactiveSrc = LockSecuredSrc; 57 | iconActiveSrc = LockUnsecuredSrc; 58 | break; 59 | case BinarySensorType.WINDOW: 60 | iconInactiveSrc = WindowClosedSrc; 61 | iconActiveSrc = WindowOpenSrc; 62 | break; 63 | default: 64 | case BinarySensorType.MOTION: 65 | iconInactiveSrc = MotionOffSrc; 66 | iconActiveSrc = MotionOnSrc; 67 | break; 68 | } 69 | 70 | return { 71 | iconActive: getIcon(iconActiveSrc), 72 | iconInactive: getIcon(iconInactiveSrc), 73 | }; 74 | }; 75 | 76 | type GetSwitchIconProps = (type: SwitchType) => { iconActive: ReactNode, iconInactive: ReactNode } 77 | export const getSwitchIcon: GetSwitchIconProps = (type: SwitchType) => { 78 | let iconActiveSrc = ''; 79 | let iconInactiveSrc = ''; 80 | 81 | switch(type) { 82 | case SwitchType.OUTLET: 83 | iconInactiveSrc = OutletOffSrc; 84 | iconActiveSrc = OutletOnSrc; 85 | break; 86 | default: 87 | case SwitchType.SWITCH: 88 | iconInactiveSrc = SwitchOffSrc; 89 | iconActiveSrc = SwitchOnSrc; 90 | break; 91 | } 92 | 93 | return { 94 | iconActive: getIcon(iconActiveSrc), 95 | iconInactive: getIcon(iconInactiveSrc), 96 | }; 97 | }; 98 | -------------------------------------------------------------------------------- /src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './accessories'; 2 | export * from './layout'; 3 | export * from './scenes'; 4 | -------------------------------------------------------------------------------- /src/components/layout/SectionLayout/SectionLayout.md: -------------------------------------------------------------------------------- 1 | ```tsx 2 | import { BinarySensorCard, BinarySensorType } from '../../accessories/BinarySensorCard'; 3 | import { LightCard } from '../../accessories/LightCard'; 4 | import { SwitchCard } from '../../accessories/SwitchCard'; 5 | import { SectionLayout } from './SectionLayout'; 6 | 7 | 8 | 12 | 16 | 21 | 22 | ``` 23 | -------------------------------------------------------------------------------- /src/components/layout/SectionLayout/SectionLayout.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, ReactNode } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | import { Title } from './Title'; 5 | 6 | 7 | const SectionLayoutContainer = styled.div` 8 | display: flex; 9 | flex-direction: column; 10 | `; 11 | 12 | interface SectionLayoutProps { 13 | children: ReactNode; 14 | title: string; 15 | } 16 | 17 | const Components = styled.div` 18 | display: flex; 19 | flex-direction: row; 20 | & > div { 21 | margin: 5px 5px 5px 0px; 22 | } 23 | `; 24 | 25 | export const SectionLayout: FC = ({ children, title }) => { 26 | return ( 27 | 28 | {title} 29 | 30 | {children} 31 | 32 | 33 | ); 34 | }; 35 | -------------------------------------------------------------------------------- /src/components/layout/SectionLayout/Title.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, ReactNode } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | const TitleContainer = styled.div` 5 | font-size: ${props => props.theme.layout.title.size}; 6 | font-weight: ${props => props.theme.layout.title.weight}; 7 | color: ${props => props.theme.layout.title.color}; 8 | margin-bottom: 10px; 9 | position: relative; 10 | `; 11 | 12 | interface TitleProps { 13 | children: ReactNode; 14 | } 15 | 16 | export const Title: FC = ({ children }) => { 17 | return ( 18 | 19 | {children} 20 | 21 | ); 22 | }; 23 | -------------------------------------------------------------------------------- /src/components/layout/SectionLayout/index.ts: -------------------------------------------------------------------------------- 1 | export { SectionLayout } from './SectionLayout'; 2 | -------------------------------------------------------------------------------- /src/components/layout/index.ts: -------------------------------------------------------------------------------- 1 | export { SectionLayout } from './SectionLayout'; 2 | -------------------------------------------------------------------------------- /src/components/scenes/SceneCard/SceneCard.md: -------------------------------------------------------------------------------- 1 | ```tsx 2 | import { ReactComponent as HeartIconSvg } from '../../../../styleguide/images/heart.svg'; 3 | 4 | const [isActive, setIsActive] = React.useState(true); 5 | 6 | 11 | } 12 | onPress={() => setIsActive(!isActive)} 13 | /> 14 | ``` 15 | -------------------------------------------------------------------------------- /src/components/scenes/SceneCard/SceneCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, ReactNode } from 'react'; 2 | import styled from '@emotion/styled'; 3 | 4 | import { ActionableCardContainer, CardIcon, CardName } from '../../common/cards'; 5 | 6 | 7 | const SceneCardContainer = styled(ActionableCardContainer)` 8 | width: ${props => props.theme.sceneCard.width}; 9 | height: ${props => props.theme.sceneCard.height}; 10 | display: flex; 11 | align-items: center; 12 | padding: 10px; 13 | `; 14 | 15 | const SceneCardIcon = styled(CardIcon)` 16 | color: ${props => props.theme.card.name.colorInactive}; 17 | display: flex; 18 | align-items: center; 19 | justify-content: center; 20 | width: 28px; 21 | max-width: 28px; 22 | `; 23 | 24 | const SceneCardName = styled(CardName)` 25 | padding: 0px 10px; 26 | flex-grow: 1; 27 | display: -webkit-box; 28 | -webkit-line-clamp: 2; 29 | -webkit-box-orient: vertical; 30 | overflow: hidden; 31 | `; 32 | 33 | interface SceneCardProps { 34 | /** Icon of the card */ 35 | readonly icon: ReactNode; 36 | /** State of the card */ 37 | readonly isActive: boolean; 38 | /** Name label of the card */ 39 | readonly name: string; 40 | /** Action triggered on press */ 41 | readonly onPress: () => void; 42 | } 43 | 44 | export const SceneCard: FC = ({ 45 | isActive, 46 | icon, 47 | name, 48 | onPress, 49 | }) => { 50 | return ( 51 | 52 | {icon} 53 | {name} 54 | 55 | ); 56 | }; 57 | -------------------------------------------------------------------------------- /src/components/scenes/SceneCard/index.ts: -------------------------------------------------------------------------------- 1 | export { SceneCard } from './SceneCard'; 2 | -------------------------------------------------------------------------------- /src/components/scenes/index.ts: -------------------------------------------------------------------------------- 1 | export { SceneCard } from './SceneCard'; 2 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './components'; 2 | export * from './types'; 3 | 4 | export { theme } from './style/theme'; 5 | export { ThemeProvider } from './style/ThemeProvider'; 6 | -------------------------------------------------------------------------------- /src/module.d.ts: -------------------------------------------------------------------------------- 1 | 2 | declare module '@emotion/react' { 3 | import '@emotion/react'; 4 | import React from 'react'; 5 | interface Colors { 6 | [key: string]: string; 7 | } 8 | export interface Theme { 9 | colors: Colors, 10 | card: any, 11 | cameraCard: any, 12 | sceneCard: any, 13 | sensorCard: any, 14 | modal: any, 15 | layout: any, 16 | } 17 | 18 | interface ThemeProviderProps { 19 | theme: Theme; 20 | } 21 | const ThemeProvider: React.SFC; 22 | } 23 | 24 | 25 | declare module 'react-mobile-picker' { 26 | import React from 'react'; 27 | 28 | export interface PickerProps { 29 | height: number; 30 | optionGroups: any; 31 | valueGroups: any; 32 | onChange: any; 33 | } 34 | 35 | const Picker: React.SFC; 36 | 37 | export default Picker; 38 | } 39 | 40 | declare module '@fseehawer/react-circular-slider' { 41 | import React from 'react'; 42 | 43 | export interface CircularSliderProps { 44 | label: any; 45 | hideLabelValue: any; 46 | appendToValue: any; 47 | min: any; 48 | max: any; 49 | width: any; 50 | knobPosition: any; 51 | knobColor: any; 52 | progressColorFrom: any; 53 | progressColorTo: any; 54 | progressSize: any; 55 | trackColor: any; 56 | trackSize: any; 57 | dataIndex: any; 58 | onChange: any; 59 | hideKnob: any; 60 | } 61 | 62 | const CircularSlider: React.SFC; 63 | 64 | export default CircularSlider; 65 | } 66 | -------------------------------------------------------------------------------- /src/resources/icons/accessories/contact-closed-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/contact-closed-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/contact-open-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/contact-open-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/door-closed-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/door-closed-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/door-open-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/door-open-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/light-bulb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 12 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/resources/icons/accessories/lock-secured-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/lock-secured-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/lock-unsecured-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/lock-unsecured-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/motion-off-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/motion-off-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/motion-on-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/motion-on-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/outlet-off-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/outlet-off-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/outlet-on-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/outlet-on-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/switch-off-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/switch-off-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/switch-on-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/switch-on-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/window-closed-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/window-closed-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/accessories/window-open-large@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/resources/icons/accessories/window-open-large@2x.png -------------------------------------------------------------------------------- /src/resources/icons/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.svg' { 2 | import React = require('react'); 3 | export const ReactComponent: React.SFC>; 4 | const src: string; 5 | export default src; 6 | } 7 | 8 | declare module '*.png'; 9 | -------------------------------------------------------------------------------- /src/resources/icons/modal-close.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/resources/icons/no-video.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/resources/icons/spinner-animated.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/strings/index.ts: -------------------------------------------------------------------------------- 1 | import { BinarySensorType, SwitchType } from '../types'; 2 | 3 | 4 | /** 5 | * Sensors 6 | */ 7 | const labelContactClosed = 'Closed'; 8 | const labelContactOpen = 'Open'; 9 | 10 | const labelDoorClosed = 'Closed'; 11 | const labelDoorOpen = 'Open'; 12 | 13 | const labelLockSecured = 'Locked'; 14 | const labelLockUnsecured = 'Unlocked'; 15 | 16 | const labelMotionOff = 'No motion'; 17 | const labelMotionOn = 'Triggered'; 18 | 19 | const labelWindowClosed = 'Closed'; 20 | const labelWindowOpen = 'Open'; 21 | 22 | /** 23 | * Switch 24 | */ 25 | const labelSwitchOn = 'On'; 26 | const labelSwitchOff = 'Off'; 27 | 28 | const labelOutletOn = 'On'; 29 | const labelOutletOff = 'Off'; 30 | 31 | 32 | export function getBinarySensorLabel(type: BinarySensorType) { 33 | let labelActive = ''; 34 | let labelInactive = ''; 35 | 36 | switch(type) { 37 | case BinarySensorType.CONTACT: 38 | labelActive = labelContactOpen; 39 | labelInactive = labelContactClosed; 40 | break; 41 | case BinarySensorType.DOOR: 42 | labelActive = labelDoorOpen; 43 | labelInactive = labelDoorClosed; 44 | break; 45 | case BinarySensorType.LOCK: 46 | labelActive = labelLockUnsecured; 47 | labelInactive = labelLockSecured; 48 | break; 49 | case BinarySensorType.WINDOW: 50 | labelActive = labelWindowOpen; 51 | labelInactive = labelWindowClosed; 52 | break; 53 | default: 54 | case BinarySensorType.MOTION: 55 | labelActive = labelMotionOn; 56 | labelInactive = labelMotionOff; 57 | break; 58 | } 59 | 60 | return { 61 | labelActive, 62 | labelInactive, 63 | }; 64 | } 65 | 66 | export function getSwitchLabel(type: SwitchType) { 67 | let labelActive = ''; 68 | let labelInactive = ''; 69 | 70 | switch(type) { 71 | case SwitchType.OUTLET: 72 | labelActive = labelOutletOn; 73 | labelInactive = labelOutletOff; 74 | break; 75 | default: 76 | case SwitchType.SWITCH: 77 | labelActive = labelSwitchOn; 78 | labelInactive = labelSwitchOff; 79 | break; 80 | } 81 | 82 | return { 83 | labelActive, 84 | labelInactive, 85 | }; 86 | } 87 | -------------------------------------------------------------------------------- /src/style/ThemeProvider.tsx: -------------------------------------------------------------------------------- 1 | import { ThemeProvider as EmotionThemeProvider } from '@emotion/react'; 2 | import React, { FC, ReactNode } from 'react'; 3 | 4 | import { theme } from './theme'; 5 | import './font.css'; 6 | 7 | export const ThemeProvider: FC<{children: ReactNode}> = ({ children }) => { 8 | return ( 9 | 10 | {children} 11 | 12 | ); 13 | }; 14 | -------------------------------------------------------------------------------- /src/style/font.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'SF UI Display'; 3 | src: url('./fonts/SFUIDisplay-Thin.woff2') format('woff2'), 4 | url('./fonts/SFUIDisplay-Thin.woff') format('woff'); 5 | font-weight: 100; 6 | font-style: normal; 7 | font-display: swap; 8 | } 9 | 10 | @font-face { 11 | font-family: 'SF UI Text'; 12 | src: url('./fonts/SFUIText-UltralightItalic.woff2') format('woff2'), 13 | url('./fonts/SFUIText-UltralightItalic.woff') format('woff'); 14 | font-weight: 200; 15 | font-style: italic; 16 | font-display: swap; 17 | } 18 | 19 | @font-face { 20 | font-family: 'SF UI Text'; 21 | src: url('./fonts/SFUIText-Ultralight.woff2') format('woff2'), 22 | url('./fonts/SFUIText-Ultralight.woff') format('woff'); 23 | font-weight: 200; 24 | font-style: normal; 25 | font-display: swap; 26 | } 27 | 28 | @font-face { 29 | font-family: 'SF UI Text'; 30 | src: url('./fonts/SFUIText-BoldItalic.woff2') format('woff2'), 31 | url('./fonts/SFUIText-BoldItalic.woff') format('woff'); 32 | font-weight: bold; 33 | font-style: italic; 34 | font-display: swap; 35 | } 36 | 37 | @font-face { 38 | font-family: 'SF UI Display'; 39 | src: url('./fonts/SFUIDisplay-Semibold.woff2') format('woff2'), 40 | url('./fonts/SFUIDisplay-Semibold.woff') format('woff'); 41 | font-weight: 600; 42 | font-style: normal; 43 | font-display: swap; 44 | } 45 | 46 | @font-face { 47 | font-family: 'SF UI Text'; 48 | src: url('./fonts/SFUIText-MediumItalic.woff2') format('woff2'), 49 | url('./fonts/SFUIText-MediumItalic.woff') format('woff'); 50 | font-weight: 500; 51 | font-style: italic; 52 | font-display: swap; 53 | } 54 | 55 | @font-face { 56 | font-family: 'SF UI Display'; 57 | src: url('./fonts/SFUIDisplay-Heavy.woff2') format('woff2'), 58 | url('./fonts/SFUIDisplay-Heavy.woff') format('woff'); 59 | font-weight: 900; 60 | font-style: normal; 61 | font-display: swap; 62 | } 63 | 64 | @font-face { 65 | font-family: 'SF UI Text'; 66 | src: url('./fonts/SFUIText-Bold.woff2') format('woff2'), 67 | url('./fonts/SFUIText-Bold.woff') format('woff'); 68 | font-weight: bold; 69 | font-style: normal; 70 | font-display: swap; 71 | } 72 | 73 | @font-face { 74 | font-family: 'SF UI Display'; 75 | src: url('./fonts/SFUIDisplay-Ultralight.woff2') format('woff2'), 76 | url('./fonts/SFUIDisplay-Ultralight.woff') format('woff'); 77 | font-weight: 200; 78 | font-style: normal; 79 | font-display: swap; 80 | } 81 | 82 | @font-face { 83 | font-family: 'SF UI Display'; 84 | src: url('./fonts/SFUIDisplay-Bold.woff2') format('woff2'), 85 | url('./fonts/SFUIDisplay-Bold.woff') format('woff'); 86 | font-weight: bold; 87 | font-style: normal; 88 | font-display: swap; 89 | } 90 | 91 | @font-face { 92 | font-family: 'SF UI Display'; 93 | src: url('./fonts/SFUIDisplay-Medium.woff2') format('woff2'), 94 | url('./fonts/SFUIDisplay-Medium.woff') format('woff'); 95 | font-weight: 500; 96 | font-style: normal; 97 | font-display: swap; 98 | } 99 | 100 | @font-face { 101 | font-family: 'SF UI Text'; 102 | src: url('./fonts/SFUIText-SemiboldItalic.woff2') format('woff2'), 103 | url('./fonts/SFUIText-SemiboldItalic.woff') format('woff'); 104 | font-weight: 600; 105 | font-style: italic; 106 | font-display: swap; 107 | } 108 | 109 | @font-face { 110 | font-family: 'SF UI Display'; 111 | src: url('./fonts/SFUIDisplay-Black.woff2') format('woff2'), 112 | url('./fonts/SFUIDisplay-Black.woff') format('woff'); 113 | font-weight: 900; 114 | font-style: normal; 115 | font-display: swap; 116 | } 117 | 118 | @font-face { 119 | font-family: 'SF UI Text'; 120 | src: url('./fonts/SFUIText-Medium.woff2') format('woff2'), 121 | url('./fonts/SFUIText-Medium.woff') format('woff'); 122 | font-weight: 500; 123 | font-style: normal; 124 | font-display: swap; 125 | } 126 | 127 | @font-face { 128 | font-family: 'SF UI Text'; 129 | src: url('./fonts/SFUIText-Heavy.woff2') format('woff2'), 130 | url('./fonts/SFUIText-Heavy.woff') format('woff'); 131 | font-weight: 900; 132 | font-style: normal; 133 | font-display: swap; 134 | } 135 | 136 | @font-face { 137 | font-family: 'SF UI Text'; 138 | src: url('./fonts/SFUIText-Semibold.woff2') format('woff2'), 139 | url('./fonts/SFUIText-Semibold.woff') format('woff'); 140 | font-weight: 600; 141 | font-style: normal; 142 | font-display: swap; 143 | } 144 | 145 | @font-face { 146 | font-family: 'SF UI Text'; 147 | src: url('./fonts/SFUIText-LightItalic.woff2') format('woff2'), 148 | url('./fonts/SFUIText-LightItalic.woff') format('woff'); 149 | font-weight: 200; 150 | font-style: italic; 151 | font-display: swap; 152 | } 153 | 154 | @font-face { 155 | font-family: 'SF UI Text'; 156 | src: url('./fonts/SFUIText-Regular.woff2') format('woff2'), 157 | url('./fonts/SFUIText-Regular.woff') format('woff'); 158 | font-weight: normal; 159 | font-style: normal; 160 | font-display: swap; 161 | } 162 | 163 | @font-face { 164 | font-family: 'SF UI Text'; 165 | src: url('./fonts/SFUIText-RegularItalic.woff2') format('woff2'), 166 | url('./fonts/SFUIText-RegularItalic.woff') format('woff'); 167 | font-weight: normal; 168 | font-style: italic; 169 | font-display: swap; 170 | } 171 | 172 | @font-face { 173 | font-family: 'SF UI Text'; 174 | src: url('./fonts/SFUIText-HeavyItalic.woff2') format('woff2'), 175 | url('./fonts/SFUIText-HeavyItalic.woff') format('woff'); 176 | font-weight: 900; 177 | font-style: italic; 178 | font-display: swap; 179 | } 180 | 181 | @font-face { 182 | font-family: 'SF UI Display'; 183 | src: url('./fonts/SFUIDisplay-Regular.woff2') format('woff2'), 184 | url('./fonts/SFUIDisplay-Regular.woff') format('woff'); 185 | font-weight: normal; 186 | font-style: normal; 187 | font-display: swap; 188 | } 189 | 190 | @font-face { 191 | font-family: 'SF UI Display'; 192 | src: url('./fonts/SFUIDisplay-Light.woff2') format('woff2'), 193 | url('./fonts/SFUIDisplay-Light.woff') format('woff'); 194 | font-weight: 200; 195 | font-style: normal; 196 | font-display: swap; 197 | } 198 | 199 | @font-face { 200 | font-family: 'SF UI Text'; 201 | src: url('./fonts/SFUIText-Light.woff2') format('woff2'), 202 | url('./fonts/SFUIText-Light.woff') format('woff'); 203 | font-weight: 200; 204 | font-style: normal; 205 | font-display: swap; 206 | } 207 | 208 | 209 | html { 210 | font-family: 'SF UI Display'; 211 | } -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Black.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Black.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Black.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Black.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Bold.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Bold.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Heavy.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Heavy.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Heavy.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Heavy.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Light.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Light.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Medium.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Medium.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Regular.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Regular.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Semibold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Semibold.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Semibold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Semibold.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Thin.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Thin.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Thin.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Thin.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Ultralight.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Ultralight.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIDisplay-Ultralight.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIDisplay-Ultralight.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Bold.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Bold.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-BoldItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-BoldItalic.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-BoldItalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-BoldItalic.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Heavy.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Heavy.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Heavy.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Heavy.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-HeavyItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-HeavyItalic.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-HeavyItalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-HeavyItalic.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Light.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Light.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-LightItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-LightItalic.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-LightItalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-LightItalic.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Medium.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Medium.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-MediumItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-MediumItalic.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-MediumItalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-MediumItalic.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Regular.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Regular.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-RegularItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-RegularItalic.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-RegularItalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-RegularItalic.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Semibold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Semibold.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Semibold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Semibold.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-SemiboldItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-SemiboldItalic.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-SemiboldItalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-SemiboldItalic.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Ultralight.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Ultralight.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-Ultralight.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-Ultralight.woff2 -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-UltralightItalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-UltralightItalic.woff -------------------------------------------------------------------------------- /src/style/fonts/SFUIText-UltralightItalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/src/style/fonts/SFUIText-UltralightItalic.woff2 -------------------------------------------------------------------------------- /src/style/theme.ts: -------------------------------------------------------------------------------- 1 | export interface Colors { 2 | [key: string]: string; 3 | } 4 | 5 | export interface Theme { 6 | colors: Colors, 7 | card: any, 8 | cameraCard: any, 9 | sceneCard: any, 10 | sensorCard: any, 11 | modal: any, 12 | layout: any, 13 | } 14 | 15 | const colors: Colors = { 16 | light1: '#FFFFFF', 17 | light2: '#F0F0F0', 18 | lightGray: '#808080', 19 | gray: '#404040', 20 | dark: '#000000', 21 | 22 | green: '#3DCC2A', 23 | 24 | backgroundActive: '#FFFFFFFF', 25 | backgroundInactive: '#FFFFFF60', 26 | 27 | lightActive: '#F8CC46', 28 | lightInactive: '#404040', 29 | }; 30 | 31 | export const theme: Theme = { 32 | colors: colors, 33 | card: { 34 | size: '100px', 35 | borderRadius: '12px', 36 | background: { 37 | colorActive: colors.backgroundActive, 38 | colorInactive: colors.backgroundInactive, 39 | }, 40 | name: { 41 | size: '12px', 42 | weight: 'bold', 43 | colorActive: colors.dark + 'FF', 44 | colorInactive: colors.dark + 'A0', 45 | }, 46 | state: { 47 | size: '12px', 48 | weight: 'bold', 49 | colorActive: colors.lightGray + 'FF', 50 | colorInactive: colors.gray + 'A0', 51 | }, 52 | light: { 53 | colorActive: colors.lightActive, 54 | colorInactive: colors.lightInactive, 55 | }, 56 | }, 57 | cameraCard: { 58 | width: '396px', 59 | height: '240px', 60 | }, 61 | sensorCard: { 62 | state: { 63 | colorActive: '#DB5242', 64 | colorInactive: colors.gray + 'A0', 65 | }, 66 | }, 67 | sceneCard: { 68 | width: '206px', 69 | height: '48px', 70 | name: { 71 | size: '14px', 72 | weight: 600, 73 | }, 74 | }, 75 | modal: { 76 | background: colors.backgroundActive, 77 | header: { 78 | title: { 79 | size: '12px', 80 | weight: 'bold', 81 | color: colors.dark, 82 | }, 83 | subtitle: { 84 | size: '12px', 85 | weight: 'bold', 86 | color: colors.lightGray, 87 | }, 88 | }, 89 | }, 90 | layout: { 91 | title: { 92 | size: '20px', 93 | weight: '200', 94 | color: colors.light1, 95 | }, 96 | }, 97 | }; 98 | -------------------------------------------------------------------------------- /src/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from './types'; 2 | -------------------------------------------------------------------------------- /src/types/types.ts: -------------------------------------------------------------------------------- 1 | export type Capabilities = { 2 | [key: string]: boolean; 3 | } 4 | 5 | export enum BinarySensorType { 6 | CONTACT, 7 | CUSTOM, 8 | DOOR, 9 | LOCK, 10 | MOTION, 11 | WINDOW, 12 | } 13 | 14 | export enum SwitchType { 15 | CUSTOM, 16 | OUTLET, 17 | SWITCH, 18 | } 19 | -------------------------------------------------------------------------------- /styleguide/Provider.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import { ThemeProvider } from '../src/style/ThemeProvider'; 4 | 5 | export default function Provider({ children }) { 6 | return ( 7 |
8 | 9 | {children} 10 | 11 |
12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /styleguide/images/camera_example.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/william57m/homekit-react-components/616200448bb04ea31503d1f555932d55cbf93ed0/styleguide/images/camera_example.jpeg -------------------------------------------------------------------------------- /styleguide/images/heart.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /styleguide/images/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.svg' { 2 | import React = require('react'); 3 | export const ReactComponent: React.SFC>; 4 | const src: string; 5 | export default src; 6 | } 7 | 8 | declare module '*.png'; 9 | -------------------------------------------------------------------------------- /styleguide/styleguide.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | webpackConfig: require('./webpack.config.js'), 5 | styleguideComponents: { 6 | Wrapper: path.join(__dirname, './Provider.js'), 7 | }, 8 | styleguideDir: '../dist_doc', 9 | propsParser: require('react-docgen-typescript').withDefaultConfig().parse, 10 | ignore: ['../src/**/index.ts'], 11 | 12 | sections: [ 13 | { 14 | name: 'UI Components', 15 | sections: [ 16 | { 17 | name: 'Accessories', 18 | exampleMode: 'collapse', 19 | usageMode: 'expand', 20 | components: [ 21 | '../src/components/accessories/BinarySensorCard/BinarySensorCard.tsx', 22 | '../src/components/accessories/CameraCard/CameraCard.tsx', 23 | '../src/components/accessories/LightCard/LightCard.tsx', 24 | '../src/components/accessories/SwitchCard/SwitchCard.tsx', 25 | '../src/components/accessories/ThermostatCard/ThermostatCard.tsx', 26 | ], 27 | }, 28 | { 29 | name: 'Scenes', 30 | exampleMode: 'collapse', 31 | usageMode: 'expand', 32 | components: '../src/components/scenes/SceneCard/SceneCard.tsx', 33 | }, 34 | { 35 | name: 'Layouts', 36 | exampleMode: 'collapse', 37 | usageMode: 'expand', 38 | components: '../src/components/layout/SectionLayout/SectionLayout.tsx', 39 | }, 40 | { 41 | name: 'Icons', 42 | exampleMode: 'collapse', 43 | usageMode: 'expand', 44 | content: '../src/components/icons/index.md', 45 | }, 46 | ], 47 | }, 48 | ], 49 | }; 50 | -------------------------------------------------------------------------------- /styleguide/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge'); 2 | 3 | const webpackConfigBase = require('../webpack.config.base'); 4 | 5 | module.exports = merge(webpackConfigBase, { 6 | 7 | }); 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "declaration": true, 5 | "declarationMap": true, 6 | "esModuleInterop": true, 7 | "experimentalDecorators": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "jsx": "react", 10 | "lib": ["dom", "dom.iterable", "esnext"], 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "skipLibCheck": true, 14 | "sourceMap": true, 15 | "strict": true, 16 | "target": "es5", 17 | }, 18 | "include": [ 19 | "**/*", 20 | "./src/module.d.ts" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /webpack.config.base.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | module: { 3 | rules: [ 4 | { 5 | test: /\.[j|t]sx?$/, 6 | exclude: /node_modules/, 7 | loader: 'babel-loader', 8 | }, 9 | { 10 | test: /\.css$/, 11 | use: ['style-loader', 'css-loader'], 12 | }, 13 | { 14 | test: /\.(woff|woff2|eot|ttf|otf)$/, 15 | use: 'url-loader', 16 | }, 17 | { 18 | test: /\.(gif|png|jpe?g)$/i, 19 | use: ['url-loader'], 20 | }, 21 | { 22 | test: /\.svg$/, 23 | use: ['@svgr/webpack', 'url-loader'], 24 | }, 25 | ], 26 | }, 27 | resolve: { 28 | extensions: ['.tsx', '.ts', '.js'], 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pkg = require('./package.json'); 3 | const nodeExternals = require('webpack-node-externals'); 4 | const { merge } = require('webpack-merge'); 5 | 6 | const webpackConfigBase = require('./webpack.config.base'); 7 | 8 | module.exports = merge(webpackConfigBase, { 9 | entry: "./src/index.ts", 10 | output: { 11 | filename: "index.js", 12 | path: path.resolve(__dirname, "dist"), 13 | library: pkg.name, 14 | libraryTarget: "umd", 15 | umdNamedDefine: true, 16 | }, 17 | mode: 'production', 18 | externals: [nodeExternals()], 19 | optimization: { 20 | minimize: false, 21 | } 22 | }); --------------------------------------------------------------------------------