-
Notifications
You must be signed in to change notification settings - Fork 14
WRP-26847: Create theming "Hello" App #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alexandrumorariu
wants to merge
25
commits into
develop
Choose a base branch
from
feature/WRP-26847
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
63c9350
added structure for theming app sample
stanca-pop-lgp 8028631
added new lines at the end of files
stanca-pop-lgp 056e246
Added color pickers and the dynamic Color hook.
alexandrumorariu cf92102
Added context for data handling.
alexandrumorariu d017f3a
added extra presets and switch items to handle dynamic skin
stanca-pop-lgp 389644a
aligned buttons in preview section
stanca-pop-lgp 01771fa
Finished all the functionality of the app.
alexandrumorariu 5c94c0f
Merge from origin.
alexandrumorariu e45cb5b
App starts with dynamicColor off.
alexandrumorariu a817852
Review fix
alexandrumorariu be8cc54
Review fixes.
alexandrumorariu 6a3e758
Review fix.
alexandrumorariu 13d463e
Git review fixes
alexandrumorariu fa589a4
Small fixes.
alexandrumorariu 7082c17
Review fix
alexandrumorariu 564f58b
Review fixes
alexandrumorariu c265c38
Update sandstone/theming-app/README.md
daniel-stoian-lgp cb9bb51
Change name of files
alexandrumorariu 3129f9a
Merge branch 'feature/WRP-26847' of https://github.com/enactjs/sample…
alexandrumorariu bea167b
WRP-28251: Create documentation for dynamic color mode (#208)
stanca-pop-lgp 35a7a44
WRP-26847: Save colors/presets using LS2 Request (#209)
adrian-cocoara-lgp 64e06e1
Review fixes.
alexandrumorariu fd0d1a7
Small fix
alexandrumorariu 40e4141
code review fixes
adrian-cocoara-lgp f9af17e
added explanatory comments in PresetPanel.js
adrian-cocoara-lgp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| node_modules | ||
|
|
||
| # testing | ||
| coverage | ||
|
|
||
| # production | ||
| build | ||
| dist | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| npm-debug.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| ## Theming App | ||
|
|
||
| A sample Enact application that uses dynamic color change feature to style the components. | ||
|
|
||
| Run `npm install` then `npm run serve` to have the app running on [http://localhost:8080](http://localhost:8080), where you can view it in your browser. | ||
|
|
||
| This app will help you choose a preset or customize the Sandstone UI components for your application. On the left side of the app, you can see all the presets and/or customizable color fields, while on the right side is the `Live Preview` area. Any value changes you make inside the color fields will be reflected in `Live Preview`. | ||
|
|
||
| #### Customize Themes | ||
|
|
||
| The radio buttons on the first Panel allow you to choose a preset including Sandstone default skin. | ||
|
|
||
| On the second Panel you can interact with color fields by changing their value inside the input field, or by clicking the colored square which will open the basic color picker. | ||
|
|
||
| #### Reset Theme | ||
|
|
||
| The `Reset` button will revert all the changes to the active selected preset. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| { | ||
| "name": "theming-app", | ||
| "version": "1.0.0", | ||
| "description": "A general template for an Enact Sandstone application.", | ||
| "author": "", | ||
| "main": "src/index.js", | ||
| "scripts": { | ||
| "serve": "enact serve", | ||
| "pack": "enact pack", | ||
| "pack-p": "enact pack -p", | ||
| "watch": "enact pack --watch", | ||
| "clean": "enact clean", | ||
| "lint": "enact lint --strict .", | ||
| "license": "enact license", | ||
| "test": "enact test", | ||
| "test-watch": "enact test --watch" | ||
| }, | ||
| "license": "UNLICENSED", | ||
| "private": true, | ||
| "repository": "", | ||
| "enact": { | ||
| "theme": "sandstone" | ||
| }, | ||
| "eslintConfig": { | ||
| "extends": "enact-proxy/strict" | ||
| }, | ||
| "eslintIgnore": [ | ||
| "node_modules/*", | ||
| "build/*", | ||
| "dist/*" | ||
| ], | ||
| "dependencies": { | ||
| "@enact/core": "^4.7.5", | ||
| "@enact/i18n": "^4.7.5", | ||
| "@enact/sandstone": "^2.7.9", | ||
| "@enact/spotlight": "^4.7.5", | ||
| "@enact/ui": "^4.7.5", | ||
| "classnames": "^2.3.2", | ||
| "ilib": "^14.18.0", | ||
| "prop-types": "^15.8.1", | ||
| "ramda": "^0.29.0", | ||
| "react": "^18.2.0", | ||
| "react-dom": "^18.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "eslint-config-enact-proxy": "^1.0.6" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "files": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [ | ||
| {"name": "pal", "pxPerRem": 12, "width": 1024, "height": 576, "aspectRatioName": "hdtv"}, | ||
| {"name": "hd", "pxPerRem": 16, "width": 1280, "height": 720, "aspectRatioName": "hdtv"}, | ||
| {"name": "fhd", "pxPerRem": 24, "width": 1920, "height": 1080, "aspectRatioName": "hdtv"}, | ||
| {"name": "uw-uxga", "pxPerRem": 24, "width": 2560, "height": 1080, "aspectRatioName": "cinema"}, | ||
| {"name": "qhd", "pxPerRem": 36, "width": 2560, "height": 1440, "aspectRatioName": "hdtv"}, | ||
| {"name": "uhd", "pxPerRem": 48, "width": 3840, "height": 2160, "aspectRatioName": "hdtv", "base": true}, | ||
| {"name": "uhd2", "pxPerRem": 96, "width": 7680, "height": 4320, "aspectRatioName": "hdtv"} | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {useState} from 'react'; | ||
| import ThemeDecorator from '@enact/sandstone/ThemeDecorator'; | ||
|
|
||
| import MainView from '../views/MainView'; | ||
| import screenTypes from '../../screenTypes.json'; | ||
|
|
||
| import {AppContext, dynamicColorsContext} from '../constants'; | ||
|
|
||
| const App = (props) => { | ||
| const [context, setContext] = useState(dynamicColorsContext); | ||
|
|
||
| return ( | ||
| <AppContext.Provider value={{context, setContext}}> | ||
| <MainView {...props} /> | ||
| </AppContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export default ThemeDecorator({ri: {screenTypes}}, App); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .app { | ||
| // general app styles | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "main": "App.js" | ||
| } |
185 changes: 185 additions & 0 deletions
185
sandstone/theming-app/src/components/ColorPicker/ColorPicker.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| import kind from '@enact/core/kind'; | ||
| import BodyText from '@enact/sandstone/BodyText'; | ||
| import Button, {ButtonBase} from '@enact/sandstone/Button'; | ||
| import Icon from '@enact/sandstone/Icon'; | ||
| import Item from '@enact/sandstone/Item'; | ||
| import Popup from '@enact/sandstone/Popup'; | ||
| import Skinnable from '@enact/sandstone/Skinnable'; | ||
| import Slider from '@enact/sandstone/Slider'; | ||
| import Spottable from '@enact/spotlight/Spottable'; | ||
| import {Cell, Column, Row} from '@enact/ui/Layout'; | ||
| import Toggleable from '@enact/ui/Toggleable'; | ||
| import PropTypes from 'prop-types'; | ||
| import compose from 'ramda/src/compose'; | ||
| import {useCallback, useEffect, useState} from 'react'; | ||
|
|
||
| import {hexToHSL, HSLToHex} from '../../hooks/utils'; | ||
|
|
||
| import componentCss from './ColorPicker.module.less'; | ||
|
|
||
| const SpottableButton = Spottable(ButtonBase); | ||
|
|
||
| const PopupContent = ({color, colorHandler, css}) => { | ||
| const [hue, setHue] = useState(0); | ||
| const [saturation, setSaturation] = useState(0); | ||
| const [lightness, setLightness] = useState(0); | ||
|
|
||
| useEffect(() => { | ||
| let {h, s, l} = hexToHSL(color); | ||
|
|
||
| setHue(h); | ||
| setSaturation(s); | ||
| setLightness(l); | ||
| }, [color]); | ||
|
|
||
| const changeHue = useCallback((ev) => { | ||
| setHue(ev.value); | ||
| }, []); | ||
|
|
||
| const changeLightness = useCallback((ev) => { | ||
| setLightness(ev.value); | ||
| }, []); | ||
|
|
||
| const changeSaturation = useCallback((ev) => { | ||
| setSaturation(ev.value); | ||
| }, []); | ||
|
|
||
| const onSliderValueChange = useCallback(() => { | ||
| colorHandler(HSLToHex({h: hue, s: saturation, l: lightness})); | ||
| }, [colorHandler, hue, lightness, saturation]); | ||
|
|
||
| return ( | ||
| <Cell className={css.colorPicker}> | ||
| <div className={css.colorsRow}> | ||
| <Column className={css.colorPickerSliders}> | ||
| <BodyText className={css.colorSliderText} css={css}>Hue {hue}</BodyText> | ||
| <Slider | ||
| className={css.colorSlider} | ||
| max={356} | ||
| min={0} | ||
| onBlur={onSliderValueChange} | ||
| onClick={onSliderValueChange} | ||
| onChange={changeHue} | ||
| value={hue} | ||
| /> | ||
| <BodyText className={css.colorSliderText} css={css}>Saturation {saturation}%</BodyText> | ||
| <Slider | ||
| className={css.colorSlider} | ||
| max={100} | ||
| min={0} | ||
| onBlur={onSliderValueChange} | ||
| onClick={onSliderValueChange} | ||
| onChange={changeSaturation} | ||
| value={saturation} | ||
| /> | ||
| <BodyText className={css.colorSliderText} css={css}>Lightness {lightness}%</BodyText> | ||
| <Slider | ||
| className={css.colorSlider} | ||
| max={100} | ||
| min={0} | ||
| onBlur={onSliderValueChange} | ||
| onClick={onSliderValueChange} | ||
| onChange={changeLightness} | ||
| value={lightness} | ||
| /> | ||
| </Column> | ||
| <div className={css.coloredDiv} style={{backgroundColor: `hsl(${hue} ,${saturation}%, ${lightness}%)`}} /> | ||
| </div> | ||
| </Cell> | ||
| ); | ||
| }; | ||
|
|
||
| PopupContent.propTypes = { | ||
| color: PropTypes.string, | ||
| colorHandler: PropTypes.func, | ||
| css: PropTypes.object, | ||
| presetColors: PropTypes.array | ||
| }; | ||
|
|
||
| const ColorPickerBase = kind({ | ||
| name: 'ColorPicker', | ||
|
|
||
| functional: true, | ||
|
|
||
| propTypes: { | ||
|
adrian-cocoara-lgp marked this conversation as resolved.
|
||
| color: PropTypes.string, | ||
| colorHandler: PropTypes.func, | ||
| css: PropTypes.object, | ||
| disabled: PropTypes.bool, | ||
| onTogglePopup: PropTypes.func, | ||
| popupOpen: PropTypes.bool, | ||
| text: PropTypes.string | ||
| }, | ||
|
|
||
| defaultProps: { | ||
| disabled: false, | ||
| popupOpen: false | ||
| }, | ||
|
|
||
| handlers: { | ||
| handleClosePopup: (ev, {onTogglePopup}) => { | ||
| onTogglePopup(); | ||
| }, | ||
| handleOpenPopup: (ev, {disabled, onTogglePopup}) => { | ||
| if (!disabled) { | ||
| onTogglePopup(); | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| styles: { | ||
| css: componentCss, | ||
| publicClassNames: true | ||
| }, | ||
|
|
||
| render: ({color, colorHandler, css, disabled, handleClosePopup, handleOpenPopup, popupOpen, text, ...rest}) => { | ||
| delete rest.onTogglePopup; | ||
|
|
||
| // eslint-disable-next-line react-hooks/rules-of-hooks | ||
| const CloseIcon = useCallback((props) => <Icon {...props} css={css} />, [css]); | ||
| const slotAfter = <SpottableButton | ||
| className={css.coloredButton} | ||
| disabled={disabled} | ||
| onClick={handleOpenPopup} | ||
| style={{backgroundColor: color}} | ||
| type="color" | ||
| />; | ||
|
|
||
| return ( | ||
| <Cell shrink className={css.colorPicker}> | ||
| <Item disabled={disabled} onClick={handleOpenPopup} slotAfter={slotAfter} {...rest}> | ||
| {text} | ||
| </Item> | ||
| <Popup | ||
| className={css.colorPopup} | ||
| css={css} | ||
| noAnimation | ||
| onClose={handleClosePopup} | ||
| open={disabled ? false : popupOpen} | ||
| position="left" | ||
| scrimType="transparent" | ||
| skin="neutral" | ||
| > | ||
| <Row> | ||
| <Cell align="center"> | ||
| <BodyText className={css.colorPopupHeader} css={css} noWrap>{text}</BodyText> | ||
| </Cell> | ||
| <Cell align="right" shrink> | ||
| <Button className={css.closeButton} css={css} iconComponent={CloseIcon} icon="closex" onClick={handleClosePopup} size="small" /> | ||
| </Cell> | ||
| </Row> | ||
| <PopupContent color={color} colorHandler={colorHandler} css={css} /> | ||
| </Popup> | ||
| </Cell> | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| const ColorPickerDecorator = compose( | ||
| Skinnable, | ||
| Toggleable({prop: 'popupOpen', toggle: 'onTogglePopup'}) | ||
| ); | ||
|
|
||
| const ColorPicker = ColorPickerDecorator(ColorPickerBase); | ||
|
|
||
| export default ColorPicker; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.