jb-core 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/theme/colors.ts +45 -5
- package/theme/stories/colors.mdx +42 -0
package/package.json
CHANGED
package/theme/colors.ts
CHANGED
|
@@ -9,14 +9,37 @@ export const colors = {
|
|
|
9
9
|
primary:{
|
|
10
10
|
main:'oklch(0.6 0.26 256)',
|
|
11
11
|
hover:getHoverColor(0.6,0.26,256),
|
|
12
|
-
pressed:getPressedColor(0.6,0.26,256)
|
|
12
|
+
pressed:getPressedColor(0.6,0.26,256),
|
|
13
|
+
lighter:getLighterColor(0.6,0.26,256),
|
|
13
14
|
},
|
|
14
15
|
secondary:{
|
|
15
16
|
main:'oklch(0.6 0.26 286)',
|
|
16
17
|
hover:getHoverColor(0.6,0.26,286),
|
|
17
18
|
pressed:getPressedColor(0.6,0.26,286),
|
|
18
|
-
|
|
19
|
+
lighter:getLighterColor(0.6,0.26,286),
|
|
20
|
+
},
|
|
21
|
+
neutral: [getNeutralColor(0),getNeutralColor(1),getNeutralColor(2),getNeutralColor(3),getNeutralColor(4),getNeutralColor(5),getNeutralColor(6),getNeutralColor(7),getNeutralColor(8),getNeutralColor(9),getNeutralColor(10)],
|
|
22
|
+
yellow:{
|
|
23
|
+
main:'oklch(0.75 0.18 70)',
|
|
24
|
+
hover:getHoverColor(0.75, 0.18, 70),
|
|
25
|
+
pressed:getPressedColor(0.75, 0.18, 70),
|
|
26
|
+
lighter:getLighterColor(0.75, 0.18, 70),
|
|
27
|
+
},
|
|
28
|
+
green:{
|
|
29
|
+
main:"oklch(0.68 0.1484 162.1)",
|
|
30
|
+
hover:getHoverColor(0.68,0.1484,162.1),
|
|
31
|
+
pressed:getPressedColor(0.68,0.1484,162.1),
|
|
32
|
+
lighter:getLighterColor(0.68,0.1484,162.1),
|
|
33
|
+
},
|
|
34
|
+
red:{
|
|
35
|
+
main:"oklch(0.6 0.22 23.21)",
|
|
36
|
+
hover:getHoverColor(0.6,0.22,23.21),
|
|
37
|
+
pressed:getPressedColor(0.6,0.22,23.21),
|
|
38
|
+
lighter:getLighterColor(0.6,0.22,23.21),
|
|
39
|
+
},
|
|
19
40
|
} as const;
|
|
41
|
+
export type JBThemeColors = typeof colors;
|
|
42
|
+
|
|
20
43
|
export function defineColors() {
|
|
21
44
|
defineColorCodes();
|
|
22
45
|
defineTextColors();
|
|
@@ -58,17 +81,23 @@ function defineColorCodes(){
|
|
|
58
81
|
inherits: true,
|
|
59
82
|
initialValue: colors.single.highlight ,
|
|
60
83
|
});
|
|
84
|
+
setCssProperty({
|
|
85
|
+
name: "--jb-yellow",
|
|
86
|
+
syntax: "<color>",
|
|
87
|
+
inherits: true,
|
|
88
|
+
initialValue: colors.yellow.main,
|
|
89
|
+
});
|
|
61
90
|
setCssProperty({
|
|
62
91
|
name: "--jb-green",
|
|
63
92
|
syntax: "<color>",
|
|
64
93
|
inherits: true,
|
|
65
|
-
initialValue:
|
|
94
|
+
initialValue: colors.green.main,
|
|
66
95
|
});
|
|
67
96
|
setCssProperty({
|
|
68
97
|
name: "--jb-red",
|
|
69
98
|
syntax: "<color>",
|
|
70
99
|
inherits: true,
|
|
71
|
-
initialValue:
|
|
100
|
+
initialValue: colors.red.main,
|
|
72
101
|
});
|
|
73
102
|
setCssProperty({
|
|
74
103
|
name: `--jb-neutral`,
|
|
@@ -81,7 +110,7 @@ function defineColorCodes(){
|
|
|
81
110
|
name: `--jb-neutral-${i}`,
|
|
82
111
|
syntax: "<color>",
|
|
83
112
|
inherits: true,
|
|
84
|
-
initialValue:
|
|
113
|
+
initialValue: colors.neutral[i],
|
|
85
114
|
});
|
|
86
115
|
}
|
|
87
116
|
}
|
|
@@ -115,4 +144,15 @@ export function getHoverColor(lightness:number, chroma:number, hue:number){
|
|
|
115
144
|
}
|
|
116
145
|
export function getPressedColor(lightness:number, chroma:number, hue:number){
|
|
117
146
|
return `oklch(${lightness - 0.1} ${chroma - 0.05} ${hue})`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function getLighterColor(lightness: number,chroma: number,hue: number) {
|
|
150
|
+
// Perceptual lightness increase (curved adjustment)
|
|
151
|
+
const newL = Math.min(lightness + 0.12 * (1 - lightness), 0.985);
|
|
152
|
+
|
|
153
|
+
// Chroma preservation with gamut safety
|
|
154
|
+
const newC = chroma * (1 - 0.15 * (newL - lightness));
|
|
155
|
+
|
|
156
|
+
// Hue preservation (no shift)
|
|
157
|
+
return `oklch(${newL.toFixed(3)} ${newC.toFixed(3)} ${hue})`;
|
|
118
158
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {Meta,ColorPalette,ColorItem, Heading, Subheading, } from '@storybook/blocks'
|
|
2
|
+
import {getNeutralColor, colors} from 'jb-core/theme/colors.ts';
|
|
3
|
+
|
|
4
|
+
<Meta title="Theme/Colors" />
|
|
5
|
+
<Heading>Color Palette</Heading>
|
|
6
|
+
<Subheading >all color are based on oklch() color space</Subheading>
|
|
7
|
+
<br/>
|
|
8
|
+
<ColorPalette>
|
|
9
|
+
<ColorItem title="single" description="" colors={{'black': colors.single.black,'white':colors.single.white}}/>
|
|
10
|
+
<ColorItem title="neutral" description="" colors={{'main':getNeutralColor(0),'d1':getNeutralColor(1),'d2':getNeutralColor(2),'d3':getNeutralColor(3),'d4':getNeutralColor(4),'d5':getNeutralColor(5),'d6':getNeutralColor(6),'d7':getNeutralColor(7),'d8':getNeutralColor(8),'d9':getNeutralColor(9),'d10':getNeutralColor(10)}}/>
|
|
11
|
+
<ColorItem title="primary" description="" colors={{'main':colors.primary.main,'lighter':colors.primary.lighter ,'hover':colors.primary.hover,'pressed':colors.primary.pressed}}/>
|
|
12
|
+
<ColorItem title="secondary" description="" colors={{'main':colors.secondary.main, 'lighter':colors.secondary.lighter,'hover':colors.secondary.hover,'pressed':colors.secondary.pressed}}/>
|
|
13
|
+
<ColorItem title="success" description="" colors={{'main':colors.green.main,'lighter':colors.green.lighter,'hover':colors.green.hover,'pressed':colors.green.pressed, 'subtle backgrounds':'oklch(0.87 0.116 171.77)', 'darker(text/icon)':'oklch(0.58 0.1227 163.94)', 'deep accents':'oklch(0.46 0.096255 165.0871)'}}/>
|
|
14
|
+
<ColorItem title="error" description="" colors={{'main':colors.red.main,"lighter":colors.red.lighter,'hover':colors.red.hover, 'pressed':colors.red.pressed, 'soft warnings':'#FF5C75', 'hover/backgrounds':'#FFA3B3','critical errors':'#D90026','dark mode':'#A3001D'}}/>
|
|
15
|
+
<ColorItem title="warning" description="" colors={{'main':colors.yellow.main, 'lighter':colors.yellow.lighter,'hover':colors.yellow.hover, 'pressed':colors.yellow.pressed}}/>
|
|
16
|
+
</ColorPalette>
|
|
17
|
+
|
|
18
|
+
<Subheading>Color Rules</Subheading>
|
|
19
|
+
|
|
20
|
+
we use `oklch()` color space for all colors in our design system. This allows us to create a consistent and harmonious color palette that is easy to use and understand.
|
|
21
|
+
<p>
|
|
22
|
+
for example primary color is `oklch(0.6 0.26 256)` which is a blue color with a lightness of 60%, chroma of 0.26, and hue of 256 degrees.
|
|
23
|
+
for hover state we add `0.07` to lightness and `0.07` to chroma so it gets a little lighter and brighter.
|
|
24
|
+
for pressed state we subtract `0.1` to lightness and `0.05` to chroma so it gets a little darker and dimmer.
|
|
25
|
+
</p>
|
|
26
|
+
<br/>
|
|
27
|
+
<Subheading>Define custom colors</Subheading>
|
|
28
|
+
<br/>
|
|
29
|
+
<p>
|
|
30
|
+
you can define your own colors by using `jb-core/theme` functions.
|
|
31
|
+
</p>
|
|
32
|
+
<p>
|
|
33
|
+
there are several function that will give you the color you want:
|
|
34
|
+
- `getNeutralColor(lightness:number)` will give you a neutral color based on the lightness value you provide. it will return a color that is in the range of 0 to 10.
|
|
35
|
+
- `getHoverColor(l:number,c:number,h:number)` will give you a hover color based on the color you provide. it will return a color that is a little lighter and brighter than the original color.
|
|
36
|
+
- `getPressedColor(l:number,c:number,h:number)` will give you a pressed color based on the color you provide. it will return a color that is a little darker and dimmer than the original color.
|
|
37
|
+
- `getLighterColor(l:number,c:number,h:number)` will give you a lighter color based on the color you provide. it will return a color that is a little lighter than the original color.
|
|
38
|
+
</p>
|
|
39
|
+
<br/>
|
|
40
|
+
<p>
|
|
41
|
+
after you define your colors you can define them in your components by using the `jb-core/theme` `defineColors` function by providing `JBThemeColors` object.
|
|
42
|
+
</p>
|