Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions samples/customize-colors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## An Enact application for showcasing the customization options for our 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.
You can focus each button to see the customization applied to it.

The easiest way to customize the color of our components is to change the value of our design tokens used in creating them.
In this case, we customized the app on three different layers to show how the changes cascade. We kept the customization
sparse to better show the process (just the background and text of a focused button).

The first thing you should do to customize an app or component should be to understand the variables that are responsible
for the expected changes. You can find the variables used in limestone here: [Limestone Repo](https://github.com/enactjs/limestone/blob/master/styles/colors.less).

For this demo I want to change the colors of a focused button (`--semantic-color-on-surface-main-focused` and `--semantic-color-surface-default-focused`).
Then I create a config file for my changes inside `src` file. There I create three different configs to use inside my app.

The first config, called `appColors`, will be applied as close to the root of the app as possible. This config will affect the
entire app. This is not recommended as our colors are responsible for multiple components and this kind of change can have
unexpected behavior.

The second config, called `containerColors`, will be applied to a container inside MainPanel. This config will apply to
the components that are inside it. This one is better to use if our container has a limited number of different components
that can be changed using a small number of variables.

The last config, called `buttonColors`, will be applied to a single component (a button). This is the best way to customize
a component as any change made inside the config will only be applied to it.

The colors changed by these configs apply in a cascade. These changes will be overwritten by further configs. In our case
`containerColors` overwrites `appColors` for the second button and `buttonColors` overwrites `containerColors` for the third.
35 changes: 35 additions & 0 deletions samples/customize-colors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "customize-colors",
"version": "1.0.0",
"description": "Limestone customization showcase 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 .",
"test": "enact test",
"test-watch": "enact test --watch"
},
"license": "Apache-2.0",
"private": true,
"repository": "",
"enact": {
"title": "Customize Colors",
"theme": "limestone"
},
"dependencies": {
"@enact/core": "^5.2.0",
"@enact/i18n": "^5.2.0",
"@enact/limestone": "../../",
"@enact/spotlight": "^5.2.0",
"@enact/ui": "^5.2.0",
"ilib": "^14.21.1",
"prop-types": "^15.8.1",
"react": "^19.1.0",
"react-dom": "^19.1.0"
}
}
3 changes: 3 additions & 0 deletions samples/customize-colors/resources/ilibmanifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": []
}
21 changes: 21 additions & 0 deletions samples/customize-colors/src/App/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import kind from '@enact/core/kind';
import ThemeDecorator from '@enact/limestone/ThemeDecorator';
import Panels from '@enact/limestone/Panels';

import MainPanel from '../views/MainPanel';

import appColors from '../colorsConfig';

const App = kind({
name: 'App',

render: (props) => (
<div style={appColors} {...props}>
<Panels>
<MainPanel />
</Panels>
</div>
)
});

export default ThemeDecorator({style: 'style'}, App);
3 changes: 3 additions & 0 deletions samples/customize-colors/src/App/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "App.js"
}
22 changes: 22 additions & 0 deletions samples/customize-colors/src/colorsConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const appColors = {
'--semantic-color-on-surface-main-focused': '#aa0000',
'--semantic-color-surface-default-focused': '#005500'
};

const buttonColors = {
'--semantic-color-on-surface-main-focused': '#aaaaaa',
'--semantic-color-surface-default-focused': '#555500'
};

const containerColors = {
'--semantic-color-on-surface-main-focused': '#aa00aa',
'--semantic-color-surface-default-focused': '#ffffff'
};

export default appColors;

export {
appColors,
buttonColors,
containerColors
};
17 changes: 17 additions & 0 deletions samples/customize-colors/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* global ENACT_PACK_ISOMORPHIC */
import {createRoot, hydrateRoot} from 'react-dom/client';

import App from './App';

const appElement = (<App />);

// In a browser environment, render instead of exporting
if (typeof window !== 'undefined') {
if (ENACT_PACK_ISOMORPHIC) {
hydrateRoot(document.getElementById('root'), appElement);
} else {
createRoot(document.getElementById('root')).render(appElement);
}
}

export default appElement;
25 changes: 25 additions & 0 deletions samples/customize-colors/src/views/MainPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import kind from '@enact/core/kind';
import BodyText from '@enact/limestone/BodyText';
import Button from '@enact/limestone/Button';
import {Column} from '@enact/ui/Layout';
import {Panel, Header} from '@enact/limestone/Panels';

import {buttonColors, containerColors} from '../colorsConfig';

const MainPanel = kind({
name: 'MainPanel',

render: (props) => (
<Panel {...props}>
<Header title="Color Customization Tutorial" />
<BodyText>Focus the buttons to see the difference in colors</BodyText>
<Button>Button changed from root</Button>
<Column style={containerColors}>
<Button>Button changed from container</Button>
<Button style={buttonColors} >Button changed from component</Button>
</Column>
</Panel>
)
});

export default MainPanel;