-
Notifications
You must be signed in to change notification settings - Fork 6
WRQ-1966: Storybook - Read custom colors from luna settings service #1610
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
adrian-cocoara-lgp
wants to merge
16
commits into
develop
Choose a base branch
from
feature/WRQ-1966-1
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 all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7f85d12
initial setup for color picker addons
adrian-cocoara-lgp 1710db1
added 5 color pickers
adrian-cocoara-lgp 3be00c0
code cleanup and initiate webos luna calls
adrian-cocoara-lgp 3560632
added a list of colorPickers when running in webos environment
adrian-cocoara-lgp c50cd68
added global decorator when running in webos environment
adrian-cocoara-lgp 5e68554
merge with develop
adrian-cocoara-lgp 0aac134
implement read colors on local
adrian-cocoara-lgp bfee888
fix lint and code cleanup
adrian-cocoara-lgp ff54cf3
override colorPicker styles and added Reset default colors button
adrian-cocoara-lgp a7a477f
fixed rendering issue when running on local
adrian-cocoara-lgp e5d7686
Merge branch 'develop' of github.com:enactjs/sandstone into feature/W…
adrian-cocoara-lgp 2c111e1
code review fixes
adrian-cocoara-lgp 7220042
minor code cleanup
adrian-cocoara-lgp 831a78e
Merge branch 'develop' of github.com:enactjs/sandstone into feature/W…
adrian-cocoara-lgp 6f8c1bd
code review fixes
adrian-cocoara-lgp 1bf82ee
added npm-shrinkwrap
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
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
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,52 @@ | ||
| import PropTypes from 'prop-types'; | ||
| import React, {useCallback} from 'react'; // eslint-disable-line | ||
| import {useGlobals} from '@storybook/api'; | ||
|
|
||
| import { | ||
| BACKGROUNDCOLOR_ADDON_ID, | ||
| BACKGROUNDCOLOR_DEFAULT_VALUE, | ||
| FOCUSBGCOLOR_ADDON_ID, | ||
| FOCUSBGCOLOR_DEFAULT_VALUE, | ||
| POPUPBGCOLOR_ADDON_ID, | ||
| POPUPBGCOLOR_DEFAULT_VALUE, | ||
| SUBTEXTCOLOR_DEFAULT_VALUE, | ||
| TEXT_ADDON_ID, | ||
| TEXT_DEFAULT_VALUE | ||
| } from './constants'; | ||
|
|
||
| const ColorPicker = ({colorPickerType}) => { | ||
| const [globals, updateGlobals] = useGlobals(); | ||
|
|
||
| const getDefaultColor = () => { | ||
| switch (colorPickerType) { | ||
| case BACKGROUNDCOLOR_ADDON_ID: | ||
| return BACKGROUNDCOLOR_DEFAULT_VALUE; | ||
| case FOCUSBGCOLOR_ADDON_ID: | ||
| return FOCUSBGCOLOR_DEFAULT_VALUE; | ||
| case POPUPBGCOLOR_ADDON_ID: | ||
| return POPUPBGCOLOR_DEFAULT_VALUE; | ||
| case TEXT_ADDON_ID: | ||
| return TEXT_DEFAULT_VALUE; | ||
| default: | ||
| return SUBTEXTCOLOR_DEFAULT_VALUE; | ||
| } | ||
| }; | ||
|
|
||
| const handleColorChange = useCallback((ev) => { | ||
| updateGlobals({[colorPickerType]: ev.target.value}); | ||
| }, [colorPickerType, updateGlobals]); | ||
|
|
||
| return ( | ||
| <input | ||
| onChange={handleColorChange} | ||
| type="color" | ||
| value={globals[colorPickerType] || getDefaultColor()} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| ColorPicker.propTypes = { | ||
| colorPickerType: PropTypes.string | ||
| }; | ||
|
|
||
| export default ColorPicker; |
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,137 @@ | ||
| // this component has been added as an alternative of built-in HTML color picker which does not work in webos environment | ||
| import Button from '@enact/sandstone/Button'; | ||
| import {ColorPicker as SandstoneColorPicker} from '@enact/sandstone/ColorPicker'; | ||
| import Scroller from '@enact/sandstone/Scroller'; | ||
| import LS2Request from '@enact/webos/LS2Request'; | ||
| import {useCallback, useContext} from 'react'; | ||
|
|
||
| import {AppContext} from './constants'; | ||
| import {generateStylesheet} from '../utils/generateStylesheet'; | ||
|
|
||
| import css from './CustomStoryDecorator.module.less'; | ||
|
|
||
| const request = new LS2Request(); | ||
|
|
||
| export const CustomStoryDecorator = () => { | ||
| const {context, setContext} = useContext(AppContext); | ||
| const {componentBackgroundColor, focusBackgroundColor, popupBackgroundColor, subtitleTextColor, textColor} = context; | ||
|
|
||
| const onColorChange = useCallback((color, newColor) => { | ||
| // a copy of the context object is created | ||
| const newContext = Object.assign({}, context); | ||
| // update the color value on the newly created object with what gets received from `event` (handleBackgroundColor, handleFocusBgColor...) | ||
| newContext[color] = newColor; | ||
| // generate the new stylesheet based on the updated color | ||
| newContext.colors = generateStylesheet( | ||
| newContext.componentBackgroundColor, | ||
| newContext.focusBackgroundColor, | ||
| newContext.popupBackgroundColor, | ||
| newContext.subtitleTextColor, | ||
| newContext.textColor | ||
| ); | ||
| setContext(newContext); | ||
|
|
||
| request.send({ | ||
| service: 'luna://com.webos.service.settings/', | ||
| method: 'setSystemSettings', | ||
| parameters: { | ||
| category: 'customUi', | ||
| settings: { | ||
| theme: JSON.stringify(newContext) | ||
| } | ||
| }, | ||
| onSuccess: () => { | ||
| console.log('setSystemSettings onSuccess'); // eslint-disable-line no-console | ||
| } | ||
| }); | ||
| }, [context, setContext]); | ||
|
|
||
| const handleComponentBgColor = useCallback((ev) => { | ||
| onColorChange('componentBackgroundColor', ev); | ||
| }, [onColorChange]); | ||
| const handleFocusBgColor = useCallback((ev) => { | ||
| onColorChange('focusBackgroundColor', ev); | ||
| }, [onColorChange]); | ||
| const handlePopupBgColor = useCallback((ev) => { | ||
| onColorChange('popupBackgroundColor', ev); | ||
| }, [onColorChange]); | ||
| const handleTextColor = useCallback((ev) => { | ||
| onColorChange('textColor', ev); | ||
| }, [onColorChange]); | ||
| const handleSubTextColor = useCallback((ev) => { | ||
| onColorChange('subtitleTextColor', ev); | ||
| }, [onColorChange]); | ||
|
|
||
| const handleResetButton = useCallback(() => { | ||
| // a copy of the context object is created | ||
| const newContext = Object.assign({}, context); | ||
| // generate the new stylesheet with default sandstone colors | ||
| newContext.colors = generateStylesheet( | ||
| newContext.componentBackgroundColor, | ||
| newContext.focusBackgroundColor, | ||
| newContext.popupBackgroundColor, | ||
| newContext.subtitleTextColor, | ||
| newContext.textColor | ||
| ); | ||
| setContext(newContext); | ||
|
|
||
| request.send({ | ||
| service: 'luna://com.webos.service.settings/', | ||
| method: 'setSystemSettings', | ||
| parameters: { | ||
| category: 'customUi', | ||
| settings: { | ||
| theme: JSON.stringify(newContext) | ||
| } | ||
| }, | ||
| onSuccess: () => { | ||
| console.log('setSystemSettings onSuccess'); // eslint-disable-line no-console | ||
| } | ||
| }); | ||
| }, []); // eslint-disable-line | ||
|
|
||
| return ( | ||
| <div className={css.colorPickersBlock}> | ||
| <Scroller className={css.scrollerColors}> | ||
| <SandstoneColorPicker | ||
| className={css.colorPicker} | ||
| css={css} | ||
| color={componentBackgroundColor} | ||
| colorHandler={handleComponentBgColor} | ||
| text="Component Background Color" | ||
| /> | ||
| <SandstoneColorPicker | ||
| className={css.colorPicker} | ||
| css={css} | ||
| color={focusBackgroundColor} | ||
| colorHandler={handleFocusBgColor} | ||
| text="Focus Background Color" | ||
| /> | ||
| <SandstoneColorPicker | ||
| className={css.colorPicker} | ||
| css={css} | ||
| color={popupBackgroundColor} | ||
| colorHandler={handlePopupBgColor} | ||
| text="Popup Background Color" | ||
| /> | ||
| <SandstoneColorPicker | ||
| className={css.colorPicker} | ||
| css={css} | ||
| color={textColor} | ||
| colorHandler={handleTextColor} | ||
| text="Text Color" | ||
| /> | ||
| <SandstoneColorPicker | ||
| className={css.colorPicker} | ||
| css={css} | ||
| color={subtitleTextColor} | ||
| colorHandler={handleSubTextColor} | ||
| text="Subtitle Text Color" | ||
| /> | ||
| <div className={css.resetButtonBlock}> | ||
| <Button className={css.resetButton} css={css} onClick={handleResetButton}>Reset default colors</Button> | ||
| </div> | ||
| </Scroller> | ||
| </div> | ||
| ); | ||
| }; | ||
61 changes: 61 additions & 0 deletions
61
samples/sampler/colors-toolbar/CustomStoryDecorator.module.less
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,61 @@ | ||
| // CustomStoryDecorator styles | ||
|
|
||
| @import '~@enact/sandstone/styles/mixins.less'; | ||
|
|
||
| // CSS variables needed to override generated custom colors | ||
| // Note: These variables need to be updated when corresponding value from sandstone/styles/colors.less is changed | ||
| @sand-text-color: #e6e6e6; | ||
| @sand-focus-bg-color-rgb: 230, 230, 230; | ||
| @sand-overlay-bg-color-rgb: 87, 94, 102; | ||
| @sand-text-color-rgb: 230, 230, 230; | ||
| @sand-progress-color-rgb: 230, 230, 230; | ||
| @sand-component-bg-color: #7d848c; | ||
| @sand-component-text-color-rgb: 230, 230, 230; | ||
|
|
||
| .colorPickersBlock { | ||
| width: 30%; | ||
| height: 65%; | ||
| position: absolute; | ||
| right: 51px; | ||
| bottom: 51px; | ||
| background: #2e3239; | ||
| border-radius: 30px; | ||
| padding: 12px; | ||
| } | ||
|
|
||
| .colorPicker { | ||
| color: @sand-text-color; | ||
|
|
||
| .focus({ | ||
| --sand-focus-bg-color-rgb: @sand-focus-bg-color-rgb; | ||
| }) | ||
| } | ||
|
|
||
| .colorPopup { | ||
| --sand-overlay-bg-color-rgb: @sand-overlay-bg-color-rgb; | ||
| --sand-text-color-rgb: @sand-text-color-rgb; | ||
| } | ||
|
|
||
| .colorPickerSliders { | ||
| .colorSlider { | ||
| --sand-focus-bg-color-rgb: @sand-focus-bg-color-rgb; | ||
| } | ||
| } | ||
|
|
||
| .scrollerColors { | ||
| --sand-progress-color-rgb: @sand-progress-color-rgb; | ||
| } | ||
|
|
||
| .resetButtonBlock { | ||
| border-top: 3px solid #e6e6e6; | ||
| padding-top: 9px; | ||
| } | ||
|
|
||
| .resetButton { | ||
| --sand-component-bg-color: @sand-component-bg-color; | ||
| --sand-component-text-color-rgb: @sand-component-text-color-rgb; | ||
|
|
||
| .focus({ | ||
| --sand-focus-bg-color-rgb: @sand-focus-bg-color-rgb; | ||
| }) | ||
| } |
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,38 @@ | ||
| import {IconButton, Icons, TooltipLinkList, WithTooltip} from '@storybook/components'; | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
|
|
||
| import ColorPicker from './ColorPicker'; | ||
|
|
||
| const ToolbarButton = React.memo(({active = true, buttonName, colorPickerType, tooltipName}) => { | ||
| const tooltipLink = { | ||
| center: <ColorPicker colorPickerType={colorPickerType} />, | ||
| id: colorPickerType, | ||
| key: colorPickerType, | ||
| left: <span style={{color: 'white'}}>{tooltipName || colorPickerType}</span>, | ||
| title: true | ||
| }; | ||
|
|
||
| const tooltip = <TooltipLinkList links={[tooltipLink]} />; | ||
|
|
||
| return ( | ||
| <WithTooltip closeOnClick tooltip={tooltip} placement="bottom" trigger="click"> | ||
| <IconButton | ||
| active={active} | ||
| key={colorPickerType} | ||
| style={{display:'flex', flexDirection:'column'}} | ||
| > | ||
| <Icons /> {buttonName || colorPickerType} | ||
| </IconButton> | ||
| </WithTooltip> | ||
| ); | ||
| }); | ||
|
|
||
| ToolbarButton.prototypes = { | ||
| active: PropTypes.boolean, | ||
| buttonName: PropTypes.string, | ||
| colorPickerType: PropTypes.string.isRequired, | ||
| tooltipName: PropTypes.string | ||
| }; | ||
|
|
||
| export default ToolbarButton; |
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,39 @@ | ||
| import {createContext} from 'react'; | ||
|
|
||
| // Object containing the default CSS values of Sandstone used for generating custom theme | ||
| // NOTE: These values need to be updated when corresponding value from sandstone/styles/colors.less is changed | ||
| export const defaultSandstoneColors = { | ||
| componentBackgroundColor: '#7d848c', // equivalent of @sand-component-bg-color - styles/colors.less | ||
| focusBackgroundColor: '#e6e6e6', // equivalent of @sand-focus-bg-color-rgb - styles/colors.less | ||
| popupBackgroundColor: '#575e66', // equivalent of @sand-overlay-bg-color-rgb - styles/colors.less | ||
| subtitleTextColor: '#abaeb3', // equivalent of @sand-text-sub-color - styles/colors.less | ||
| textColor: '#e6e6e6' // equivalent of @sand-text-color-rgb - styles/colors.less | ||
| }; | ||
|
|
||
| export const customColorsContext = { | ||
| activeTheme: 'defaultTheme', | ||
| componentBackgroundColor: defaultSandstoneColors.componentBackgroundColor, | ||
| focusBackgroundColor: defaultSandstoneColors.focusBackgroundColor, | ||
| popupBackgroundColor: defaultSandstoneColors.popupBackgroundColor, | ||
| subtitleTextColor: defaultSandstoneColors.subtitleTextColor, | ||
| textColor: defaultSandstoneColors.textColor | ||
| }; | ||
|
|
||
| export const AppContext = createContext(null); | ||
|
|
||
| export const BACKGROUNDCOLOR_ADDON_ID = "componentBackgroundColor"; | ||
| export const BACKGROUNDCOLOR_DEFAULT_VALUE = defaultSandstoneColors.componentBackgroundColor; | ||
|
|
||
| export const FOCUSBGCOLOR_ADDON_ID = "focusBackgroundColor"; | ||
| export const FOCUSBGCOLOR_DEFAULT_VALUE = defaultSandstoneColors.focusBackgroundColor; | ||
|
|
||
| export const POPUPBGCOLOR_ADDON_ID = "popupBackgroundColor"; | ||
| export const POPUPBGCOLOR_DEFAULT_VALUE = defaultSandstoneColors.popupBackgroundColor; | ||
|
|
||
| export const SUBTEXTCOLOR_ADDON_ID = "subtitleTextColor"; | ||
| export const SUBTEXTCOLOR_DEFAULT_VALUE = defaultSandstoneColors.subtitleTextColor; | ||
|
|
||
| export const TEXT_ADDON_ID = "textColor"; | ||
| export const TEXT_DEFAULT_VALUE = defaultSandstoneColors.textColor; | ||
|
|
||
| export const TOOLBAR_ADDON_ID = "toolbar-colors"; |
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.