Skip to content
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

WRP-26847: Create theming "Hello" App #206

Draft
wants to merge 25 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 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 Sep 13, 2023
8028631
added new lines at the end of files
stanca-pop-lgp Sep 13, 2023
056e246
Added color pickers and the dynamic Color hook.
alexandrumorariu Sep 14, 2023
cf92102
Added context for data handling.
alexandrumorariu Sep 14, 2023
d017f3a
added extra presets and switch items to handle dynamic skin
stanca-pop-lgp Sep 14, 2023
389644a
aligned buttons in preview section
stanca-pop-lgp Sep 14, 2023
01771fa
Finished all the functionality of the app.
alexandrumorariu Sep 15, 2023
5c94c0f
Merge from origin.
alexandrumorariu Sep 15, 2023
e45cb5b
App starts with dynamicColor off.
alexandrumorariu Sep 15, 2023
a817852
Review fix
alexandrumorariu Sep 15, 2023
be8cc54
Review fixes.
alexandrumorariu Sep 15, 2023
6a3e758
Review fix.
alexandrumorariu Sep 20, 2023
13d463e
Git review fixes
alexandrumorariu Sep 20, 2023
fa589a4
Small fixes.
alexandrumorariu Sep 20, 2023
7082c17
Review fix
alexandrumorariu Sep 20, 2023
564f58b
Review fixes
alexandrumorariu Sep 20, 2023
c265c38
Update sandstone/theming-app/README.md
daniel-stoian-lgp Sep 20, 2023
cb9bb51
Change name of files
alexandrumorariu Sep 21, 2023
3129f9a
Merge branch 'feature/WRP-26847' of https://github.com/enactjs/sample…
alexandrumorariu Sep 21, 2023
bea167b
WRP-28251: Create documentation for dynamic color mode (#208)
stanca-pop-lgp Sep 29, 2023
35a7a44
WRP-26847: Save colors/presets using LS2 Request (#209)
adrian-cocoara-lgp Oct 12, 2023
64e06e1
Review fixes.
alexandrumorariu Oct 19, 2023
fd0d1a7
Small fix
alexandrumorariu Oct 19, 2023
40e4141
code review fixes
adrian-cocoara-lgp Oct 20, 2023
f9af17e
added explanatory comments in PresetPanel.js
adrian-cocoara-lgp Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sandstone/theming-app/.gitignore
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
17 changes: 17 additions & 0 deletions sandstone/theming-app/README.md
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 presets including Sandstone default skin.
daniel-stoian-lgp marked this conversation as resolved.
Show resolved Hide resolved

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.
48 changes: 48 additions & 0 deletions sandstone/theming-app/package.json
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"
}
}
3 changes: 3 additions & 0 deletions sandstone/theming-app/resources/ilibmanifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": []
}
9 changes: 9 additions & 0 deletions sandstone/theming-app/screenTypes.json
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"}
]
19 changes: 19 additions & 0 deletions sandstone/theming-app/src/App/App.js
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);
3 changes: 3 additions & 0 deletions sandstone/theming-app/src/App/App.module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.app {
// general app styles
}
3 changes: 3 additions & 0 deletions sandstone/theming-app/src/App/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "App.js"
}
194 changes: 194 additions & 0 deletions sandstone/theming-app/src/components/ColorPicker/ColorPicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
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,
adrian-cocoara-lgp marked this conversation as resolved.
Show resolved Hide resolved

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.
Show resolved Hide 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;
Loading