-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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 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 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,26 @@ | ||
import { Canvas, Meta, Story } from '@storybook/blocks' | ||
import { ColorStatic } from './ColorSchemes' | ||
|
||
<Meta title="ColorSchemes" /> | ||
|
||
# Dynamic Color | ||
|
||
```ts | ||
// provide some helper function | ||
import { type Theme, themeFromHexString, themeFromImageOrFile } from "soda-material/dist/utils/theme.js" | ||
const theme: Theme = themeFromHexString('#6750a4') | ||
const theme: Theme = await themeFromImageOrFile(/* accept HTMLImageElement or File object */) | ||
|
||
// apply theme | ||
import { applyThemeForSoda } from 'soda-material/dist/utils/theme.js' | ||
applyThemeForSoda('#6750a4') | ||
applyThemeForSoda(theme) | ||
``` | ||
|
||
It's actually a module that provides some helper function and re-export the [@material/material-color-utilities](https://npm.im/@material/material-color-utilities) package. | ||
|
||
# Color Schemes | ||
|
||
Refer to [https://m3.material.io/styles/color/static/baseline](https://m3.material.io/styles/color/static/baseline) | ||
|
||
<ColorStatic /> |
This file contains 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,72 @@ | ||
const COLOR_TOKEN_MAP = { | ||
'surface-tint': ['', 'color'], | ||
'on-error': ['', 'container'], | ||
error: ['', 'container'], | ||
'on-tertiary': ['', 'container'], | ||
tertiary: ['', 'container'], | ||
shadow: [''], | ||
outline: ['', 'variant'], | ||
'on-background': [''], | ||
background: [''], | ||
'inverse-on-surface': [''], | ||
'inverse-surface': [''], | ||
'on-surface': ['', 'variant'], | ||
surface: [ | ||
'', | ||
'variant', | ||
'container', | ||
'container-lowest', | ||
'container-low', | ||
'container-high', | ||
'container-highest', | ||
], | ||
'on-secondary': ['', 'container'], | ||
secondary: ['', 'container'], | ||
'inverse-primary': [''], | ||
'on-primary': ['', 'container'], | ||
primary: ['', 'container'], | ||
} | ||
|
||
export function ColorStatic() { | ||
return Object.entries(COLOR_TOKEN_MAP).map(([prefix, decorates]) => ( | ||
<section key={prefix}> | ||
<ul | ||
style={{ | ||
padding: '0', | ||
listStyle: 'none', | ||
display: 'grid', | ||
gridTemplateColumns: | ||
'repeat(auto-fill, minmax(360px, 1fr))', | ||
gap: '.3rem', | ||
}} | ||
> | ||
{decorates.map((decorate) => { | ||
const name = decorate ? `${prefix}-${decorate}` : prefix | ||
const color = `var(--md-sys-color-${name})` | ||
return ( | ||
<li | ||
style={{ | ||
background: color, | ||
margin: '0', | ||
padding: '.5rem 1rem', | ||
boxSizing: 'border-box', | ||
borderRadius: '.25rem', | ||
border: 'solid 1px var(--md-sys-color-outline)', | ||
}} | ||
> | ||
<span | ||
style={{ | ||
color, | ||
filter: 'grayscale(1) contrast(999) invert(1)', | ||
userSelect: 'all', | ||
}} | ||
> | ||
{color} | ||
</span> | ||
</li> | ||
) | ||
})} | ||
</ul> | ||
</section> | ||
)) | ||
} |
This file contains 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