@xanui/core 1.1.2 → 1.1.5
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/ServerStyleTags.js +3 -0
- package/ServerStyleTags.js.map +1 -0
- package/ServerStyleTags.mjs +3 -0
- package/ServerStyleTags.mjs.map +1 -0
- package/Tag/cssPropList.js +186 -0
- package/Tag/cssPropList.js.map +1 -0
- package/{src/Tag/cssPropList.ts → Tag/cssPropList.mjs} +2 -7
- package/Tag/cssPropList.mjs.map +1 -0
- package/Tag/index.js +6 -0
- package/Tag/index.js.map +1 -0
- package/Tag/index.mjs +6 -0
- package/Tag/index.mjs.map +1 -0
- package/Tag/useTagProps.js +21 -0
- package/Tag/useTagProps.js.map +1 -0
- package/Tag/useTagProps.mjs +21 -0
- package/Tag/useTagProps.mjs.map +1 -0
- package/Transition/index.js +93 -0
- package/Transition/index.js.map +1 -0
- package/Transition/index.mjs +93 -0
- package/Transition/index.mjs.map +1 -0
- package/Transition/variants.js +158 -0
- package/Transition/variants.js.map +1 -0
- package/{src/Transition/variants.ts → Transition/variants.mjs} +44 -64
- package/Transition/variants.mjs.map +1 -0
- package/breakpoint/BreakpointProvider.js +43 -0
- package/breakpoint/BreakpointProvider.js.map +1 -0
- package/breakpoint/BreakpointProvider.mjs +43 -0
- package/breakpoint/BreakpointProvider.mjs.map +1 -0
- package/breakpoint/useBreakpoint.js +23 -0
- package/breakpoint/useBreakpoint.js.map +1 -0
- package/breakpoint/useBreakpoint.mjs +23 -0
- package/breakpoint/useBreakpoint.mjs.map +1 -0
- package/breakpoint/useBreakpointProps.js +42 -0
- package/breakpoint/useBreakpointProps.js.map +1 -0
- package/breakpoint/useBreakpointProps.mjs +42 -0
- package/breakpoint/useBreakpointProps.mjs.map +1 -0
- package/css/aliases.js +29 -0
- package/css/aliases.js.map +1 -0
- package/css/aliases.mjs +29 -0
- package/css/aliases.mjs.map +1 -0
- package/{src/css/getProps.ts → css/getProps.js} +15 -21
- package/css/getProps.js.map +1 -0
- package/css/getProps.mjs +32 -0
- package/css/getProps.mjs.map +1 -0
- package/{src/css/getValue.ts → css/getValue.js} +40 -65
- package/css/getValue.js.map +1 -0
- package/css/getValue.mjs +92 -0
- package/css/getValue.mjs.map +1 -0
- package/css/index.js +55 -0
- package/css/index.js.map +1 -0
- package/css/index.mjs +55 -0
- package/css/index.mjs.map +1 -0
- package/index.d.ts +629 -0
- package/index.js +1 -0
- package/index.js.map +1 -0
- package/index.mjs +1 -0
- package/index.mjs.map +1 -0
- package/isWindow.js +1 -0
- package/isWindow.js.map +1 -0
- package/isWindow.mjs +1 -0
- package/isWindow.mjs.map +1 -0
- package/package.json +50 -51
- package/theme/ThemeCssVars.js +5 -0
- package/theme/ThemeCssVars.js.map +1 -0
- package/theme/ThemeCssVars.mjs +5 -0
- package/theme/ThemeCssVars.mjs.map +1 -0
- package/theme/ThemeDefaultOptions.js +131 -0
- package/theme/ThemeDefaultOptions.js.map +1 -0
- package/{src/theme/ThemeDefaultOptions.ts → theme/ThemeDefaultOptions.mjs} +17 -32
- package/theme/ThemeDefaultOptions.mjs.map +1 -0
- package/theme/ThemeProvider.js +88 -0
- package/theme/ThemeProvider.js.map +1 -0
- package/theme/ThemeProvider.mjs +88 -0
- package/theme/ThemeProvider.mjs.map +1 -0
- package/theme/core.js +18 -0
- package/theme/core.js.map +1 -0
- package/theme/core.mjs +18 -0
- package/theme/core.mjs.map +1 -0
- package/theme/createColor.js +46 -0
- package/theme/createColor.js.map +1 -0
- package/theme/createColor.mjs +46 -0
- package/theme/createColor.mjs.map +1 -0
- package/theme/createTheme.js +21 -0
- package/theme/createTheme.js.map +1 -0
- package/theme/createTheme.mjs +21 -0
- package/theme/createTheme.mjs.map +1 -0
- package/theme/createThemeSwitcher.js +12 -0
- package/theme/createThemeSwitcher.js.map +1 -0
- package/theme/createThemeSwitcher.mjs +12 -0
- package/theme/createThemeSwitcher.mjs.map +1 -0
- package/theme/index.js +2 -0
- package/theme/index.js.map +1 -0
- package/theme/index.mjs +2 -0
- package/theme/index.mjs.map +1 -0
- package/useAnimation.js +25 -0
- package/useAnimation.js.map +1 -0
- package/{src/useAnimation.ts → useAnimation.mjs} +10 -25
- package/useAnimation.mjs.map +1 -0
- package/useColorTemplate.js +6 -0
- package/useColorTemplate.js.map +1 -0
- package/useColorTemplate.mjs +6 -0
- package/useColorTemplate.mjs.map +1 -0
- package/useInterface.js +8 -0
- package/useInterface.js.map +1 -0
- package/useInterface.mjs +8 -0
- package/useInterface.mjs.map +1 -0
- package/main.tsx +0 -97
- package/src/ServerStyleTags.tsx +0 -12
- package/src/Tag/index.tsx +0 -11
- package/src/Tag/types.ts +0 -183
- package/src/Tag/useTagProps.ts +0 -28
- package/src/Transition/index.tsx +0 -148
- package/src/breakpoint/index.tsx +0 -52
- package/src/breakpoint/useBreakpoint.ts +0 -31
- package/src/breakpoint/useBreakpointProps.ts +0 -57
- package/src/css/aliases.ts +0 -35
- package/src/css/index.ts +0 -78
- package/src/css/types.ts +0 -60
- package/src/index.ts +0 -34
- package/src/isWindow.ts +0 -3
- package/src/theme/ThemeCssVars.ts +0 -107
- package/src/theme/ThemeProvider.tsx +0 -140
- package/src/theme/core.ts +0 -21
- package/src/theme/createColor.ts +0 -53
- package/src/theme/createTheme.ts +0 -33
- package/src/theme/createThemeSwitcher.ts +0 -18
- package/src/theme/index.tsx +0 -17
- package/src/theme/types.ts +0 -181
- package/src/useColorTemplate.ts +0 -11
- package/src/useInterface.ts +0 -13
- package/tsconfig.json +0 -28
package/src/css/index.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import getValue from "./getValue"
|
|
2
|
-
import getProps from "./getProps"
|
|
3
|
-
import aliases from "./aliases"
|
|
4
|
-
import { Aliases, BreakpointKeys, CSSOptionProps, CSSProps } from './types'
|
|
5
|
-
import { css as _css } from "oncss"
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
getValue,
|
|
9
|
-
getProps
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const breakpoints = {
|
|
13
|
-
xs: 0,
|
|
14
|
-
sm: 600,
|
|
15
|
-
md: 900,
|
|
16
|
-
lg: 1200,
|
|
17
|
-
xl: 1536
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const css = (props: CSSProps, options?: CSSOptionProps) => {
|
|
21
|
-
const cssOptions: CSSOptionProps = {
|
|
22
|
-
...options,
|
|
23
|
-
breakpoints,
|
|
24
|
-
aliases,
|
|
25
|
-
getValue: (p: any, v: any, _c: any, dept) => {
|
|
26
|
-
if (options?.getValue) {
|
|
27
|
-
let _val = options?.getValue(p, v, _c, dept)
|
|
28
|
-
if (_val) return _val
|
|
29
|
-
}
|
|
30
|
-
return getValue(p, v, _c)
|
|
31
|
-
},
|
|
32
|
-
getProps: (p: any, v: any, _c: any, dept) => {
|
|
33
|
-
if (options?.getProps) {
|
|
34
|
-
let _p = options?.getProps(p, v, _c, dept)
|
|
35
|
-
if (_p) return _p
|
|
36
|
-
}
|
|
37
|
-
return getProps(p, v, _c)
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
return _css<Aliases, BreakpointKeys>(props, cssOptions)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const adjustColor = (hex: string, factor: number) => {
|
|
44
|
-
|
|
45
|
-
hex = hex.replace(/^#/, '')
|
|
46
|
-
|
|
47
|
-
let r = parseInt(hex.slice(0, 2), 16)
|
|
48
|
-
let g = parseInt(hex.slice(2, 4), 16)
|
|
49
|
-
let b = parseInt(hex.slice(4, 6), 16)
|
|
50
|
-
|
|
51
|
-
r = Math.floor(r * factor)
|
|
52
|
-
g = Math.floor(g * factor)
|
|
53
|
-
b = Math.floor(b * factor)
|
|
54
|
-
|
|
55
|
-
r = Math.min(255, Math.max(0, r))
|
|
56
|
-
g = Math.min(255, Math.max(0, g))
|
|
57
|
-
b = Math.min(255, Math.max(0, b))
|
|
58
|
-
|
|
59
|
-
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const adjustTextContrast = (color: string) => {
|
|
63
|
-
color = color.replace(/^#/, '')
|
|
64
|
-
const r = parseInt(color.slice(0, 2), 16);
|
|
65
|
-
const g = parseInt(color.slice(2, 4), 16);
|
|
66
|
-
const b = parseInt(color.slice(4, 6), 16);
|
|
67
|
-
|
|
68
|
-
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
69
|
-
return luminance > 0.5 ? '#111111' : '#FFFFFF';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const alpha = (color: string, opacity = 1) => {
|
|
73
|
-
if (typeof opacity !== 'number') return color
|
|
74
|
-
let _opacity = opacity * 100
|
|
75
|
-
if (!color.startsWith("#")) throw new Error(`color must be hex`)
|
|
76
|
-
return (color + (`0${Math.round((255 / 100) * _opacity).toString(16)}`.slice(-2))).toUpperCase();
|
|
77
|
-
};
|
|
78
|
-
|
package/src/css/types.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import * as CSS from 'csstype'
|
|
2
|
-
import { ColorsRefTypes, TypographyRefTypes, ThemeOptions, } from '../theme/types';
|
|
3
|
-
import * as oncss from 'oncss'
|
|
4
|
-
export type FN = (theme: ThemeOptions) => string | number
|
|
5
|
-
export type CSSBreakpointType = { [key in BreakpointKeys]: string | number }
|
|
6
|
-
export type CSSValueType<T extends keyof CSS.Properties> = CSS.Properties[T] | Partial<CSSBreakpointType> | number
|
|
7
|
-
|
|
8
|
-
export type Aliases = {
|
|
9
|
-
bgcolor?: CSSValueType<'background'> | ColorsRefTypes;
|
|
10
|
-
bgimage?: CSSValueType<'backgroundImage'>;
|
|
11
|
-
bg?: CSSValueType<'background'> | ColorsRefTypes;
|
|
12
|
-
p?: CSSValueType<'padding'>;
|
|
13
|
-
pt?: CSSValueType<'padding'>;
|
|
14
|
-
pr?: CSSValueType<'padding'>;
|
|
15
|
-
pb?: CSSValueType<'padding'>;
|
|
16
|
-
pl?: CSSValueType<'padding'>;
|
|
17
|
-
px?: CSSValueType<'padding'>;
|
|
18
|
-
py?: CSSValueType<'margin'>;
|
|
19
|
-
m?: CSSValueType<'margin'>;
|
|
20
|
-
mt?: CSSValueType<'margin'>;
|
|
21
|
-
mr?: CSSValueType<'margin'>;
|
|
22
|
-
mb?: CSSValueType<'margin'>;
|
|
23
|
-
ml?: CSSValueType<'margin'>;
|
|
24
|
-
mx?: CSSValueType<'margin'>;
|
|
25
|
-
my?: CSSValueType<'margin'>;
|
|
26
|
-
size?: CSSValueType<'width'>;
|
|
27
|
-
spacing?: Partial<CSSBreakpointType> | number;
|
|
28
|
-
|
|
29
|
-
radius?: CSSValueType<'borderRadius'> | number;
|
|
30
|
-
borderRadius?: CSSValueType<'borderRadius'> | number;
|
|
31
|
-
shadow?: CSSValueType<'boxShadow'> | number;
|
|
32
|
-
flexBox?: boolean;
|
|
33
|
-
flexRow?: boolean;
|
|
34
|
-
flexColumn?: boolean;
|
|
35
|
-
flexWraped?: boolean;
|
|
36
|
-
direction?: "row" | "column" | CSSValueType<'direction'>;
|
|
37
|
-
gap?: CSSValueType<'gap'>;
|
|
38
|
-
|
|
39
|
-
color?: CSSValueType<'color'> | ColorsRefTypes;
|
|
40
|
-
width?: CSSValueType<'width'> | BreakpointKeys;
|
|
41
|
-
height?: CSSValueType<'height'>
|
|
42
|
-
borderColor?: CSSValueType<'backgroundColor'> | ColorsRefTypes;
|
|
43
|
-
|
|
44
|
-
fontFamily?: CSSValueType<"fontFamily"> | "default";
|
|
45
|
-
fontSize?: CSSValueType<"fontSize"> | TypographyRefTypes;
|
|
46
|
-
minWidth?: CSSValueType<"minWidth"> | BreakpointKeys;
|
|
47
|
-
maxWidth?: CSSValueType<"maxWidth"> | BreakpointKeys;
|
|
48
|
-
minHeight?: CSSValueType<"minHeight">
|
|
49
|
-
maxHeight?: CSSValueType<"maxHeight">
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
export type BreakpointKeys = "xs" | "sm" | "md" | "lg" | "xl"
|
|
54
|
-
|
|
55
|
-
export type CSSProps = oncss.CSSProps<Aliases, BreakpointKeys>
|
|
56
|
-
export type CSSOptionProps = oncss.CSSOptionProps<Aliases, BreakpointKeys>
|
|
57
|
-
|
|
58
|
-
export type GlobalCSS = {
|
|
59
|
-
[key: string]: oncss.CSSPropsWithoutGlobal<Aliases, BreakpointKeys>;
|
|
60
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import Tag from './Tag'
|
|
2
|
-
import useTagProps from './Tag/useTagProps'
|
|
3
|
-
import useAnimation from './useAnimation'
|
|
4
|
-
import useColorTemplate from './useColorTemplate'
|
|
5
|
-
import useBreakpoint from './breakpoint/useBreakpoint'
|
|
6
|
-
import useBreakpointProps from './breakpoint/useBreakpointProps'
|
|
7
|
-
import ServerStyleTags from './ServerStyleTags'
|
|
8
|
-
import isWindow from './isWindow'
|
|
9
|
-
import useInterface from './useInterface'
|
|
10
|
-
import Transition from './Transition'
|
|
11
|
-
|
|
12
|
-
export * from './css'
|
|
13
|
-
export * from "./theme"
|
|
14
|
-
export * from './css/types'
|
|
15
|
-
export * from './Tag/types'
|
|
16
|
-
export * from './theme/types'
|
|
17
|
-
export * from './useColorTemplate'
|
|
18
|
-
export * from './useAnimation'
|
|
19
|
-
export type * from './Transition'
|
|
20
|
-
export type * from './Tag/types'
|
|
21
|
-
export type { useBreakpointPropsType } from './breakpoint/useBreakpointProps'
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
Tag,
|
|
25
|
-
useTagProps,
|
|
26
|
-
useAnimation,
|
|
27
|
-
Transition,
|
|
28
|
-
useColorTemplate,
|
|
29
|
-
ServerStyleTags,
|
|
30
|
-
useBreakpoint,
|
|
31
|
-
useBreakpointProps,
|
|
32
|
-
isWindow,
|
|
33
|
-
useInterface
|
|
34
|
-
}
|
package/src/isWindow.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { ThemeOptions } from "./types";
|
|
2
|
-
|
|
3
|
-
const ThemeCssVars = (theme: ThemeOptions) => {
|
|
4
|
-
|
|
5
|
-
const shadows: any = {}
|
|
6
|
-
theme.shadow.forEach((s, i) => shadows[`--shadow-${i}`] = s)
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
"--bp-xs": theme.breakpoints.xs,
|
|
10
|
-
"--bp-sm": theme.breakpoints.sm,
|
|
11
|
-
"--bp-md": theme.breakpoints.md,
|
|
12
|
-
"--bp-lg": theme.breakpoints.lg,
|
|
13
|
-
"--bp-xl": theme.breakpoints.xl,
|
|
14
|
-
|
|
15
|
-
"--font-family": theme.typography.fontFamily,
|
|
16
|
-
"--font-h1": `${theme.typography.h1.fontWeight} ${theme.typography.h1.fontSize}px/${theme.typography.h1.lineHeight} ${theme.typography.fontFamily}`,
|
|
17
|
-
"--font-h2": `${theme.typography.h2.fontWeight} ${theme.typography.h2.fontSize}px/${theme.typography.h2.lineHeight} ${theme.typography.fontFamily}`,
|
|
18
|
-
"--font-h3": `${theme.typography.h3.fontWeight} ${theme.typography.h3.fontSize}px/${theme.typography.h3.lineHeight} ${theme.typography.fontFamily}`,
|
|
19
|
-
"--font-h4": `${theme.typography.h4.fontWeight} ${theme.typography.h4.fontSize}px/${theme.typography.h4.lineHeight} ${theme.typography.fontFamily}`,
|
|
20
|
-
"--font-h5": `${theme.typography.h5.fontWeight} ${theme.typography.h5.fontSize}px/${theme.typography.h5.lineHeight} ${theme.typography.fontFamily}`,
|
|
21
|
-
"--font-h6": `${theme.typography.h6.fontWeight} ${theme.typography.h6.fontSize}px/${theme.typography.h6.lineHeight} ${theme.typography.fontFamily}`,
|
|
22
|
-
"--font-text": `${theme.typography.text.fontWeight} ${theme.typography.text.fontSize}px/${theme.typography.text.lineHeight} ${theme.typography.fontFamily}`,
|
|
23
|
-
"--font-button": `${theme.typography.button.fontWeight} ${theme.typography.button.fontSize}px/${theme.typography.button.lineHeight} ${theme.typography.fontFamily}`,
|
|
24
|
-
"--font-small": `${theme.typography.small.fontWeight} ${theme.typography.small.fontSize}px/${theme.typography.small.lineHeight} ${theme.typography.fontFamily}`,
|
|
25
|
-
|
|
26
|
-
"--fontsize-h1": `${theme.typography.h1.fontSize}px`,
|
|
27
|
-
"--fontsize-h2": `${theme.typography.h2.fontSize}px`,
|
|
28
|
-
"--fontsize-h3": `${theme.typography.h3.fontSize}px`,
|
|
29
|
-
"--fontsize-h4": `${theme.typography.h4.fontSize}px`,
|
|
30
|
-
"--fontsize-h5": `${theme.typography.h5.fontSize}px`,
|
|
31
|
-
"--fontsize-h6": `${theme.typography.h6.fontSize}px`,
|
|
32
|
-
"--fontsize-text": `${theme.typography.text.fontSize}px`,
|
|
33
|
-
"--fontsize-button": `${theme.typography.button.fontSize}px`,
|
|
34
|
-
"--fontsize-small": `${theme.typography.small.fontSize}px`,
|
|
35
|
-
|
|
36
|
-
"--fontweight-h1": theme.typography.h1.fontWeight + "",
|
|
37
|
-
"--fontweight-h2": theme.typography.h2.fontWeight + "",
|
|
38
|
-
"--fontweight-h3": theme.typography.h3.fontWeight + "",
|
|
39
|
-
"--fontweight-h4": theme.typography.h4.fontWeight + "",
|
|
40
|
-
"--fontweight-h5": theme.typography.h5.fontWeight + "",
|
|
41
|
-
"--fontweight-h6": theme.typography.h6.fontWeight + "",
|
|
42
|
-
"--fontweight-text": theme.typography.text.fontWeight + "",
|
|
43
|
-
"--fontweight-button": theme.typography.button.fontWeight + "",
|
|
44
|
-
"--fontweight-small": theme.typography.small.fontWeight + "",
|
|
45
|
-
|
|
46
|
-
"--lineheight-h1": theme.typography.h1.lineHeight + "",
|
|
47
|
-
"--lineheight-h2": theme.typography.h2.lineHeight + "",
|
|
48
|
-
"--lineheight-h3": theme.typography.h3.lineHeight + "",
|
|
49
|
-
"--lineheight-h4": theme.typography.h4.lineHeight + "",
|
|
50
|
-
"--lineheight-h5": theme.typography.h5.lineHeight + "",
|
|
51
|
-
"--lineheight-h6": theme.typography.h6.lineHeight + "",
|
|
52
|
-
"--lineheight-text": theme.typography.text.lineHeight + "",
|
|
53
|
-
"--lineheight-button": theme.typography.button.lineHeight + "",
|
|
54
|
-
"--lineheight-small": theme.typography.small.lineHeight + "",
|
|
55
|
-
|
|
56
|
-
"--color-text": theme.colors.text.primary,
|
|
57
|
-
"--color-text-primary": theme.colors.text.primary,
|
|
58
|
-
"--color-text-secondary": theme.colors.text.secondary,
|
|
59
|
-
|
|
60
|
-
"--color-background": theme.colors.background.primary,
|
|
61
|
-
"--color-background-primary": theme.colors.background.primary,
|
|
62
|
-
"--color-background-secondary": theme.colors.background.secondary,
|
|
63
|
-
"--color-background-alpha": theme.colors.background.alpha,
|
|
64
|
-
|
|
65
|
-
"--color-divider": theme.colors.divider,
|
|
66
|
-
|
|
67
|
-
"--color-brand": theme.colors.brand.primary,
|
|
68
|
-
"--color-brand-primary": theme.colors.brand.primary,
|
|
69
|
-
"--color-brand-secondary": theme.colors.brand.secondary,
|
|
70
|
-
"--color-brand-alpha": theme.colors.brand.alpha,
|
|
71
|
-
"--color-brand-text": theme.colors.brand.text,
|
|
72
|
-
|
|
73
|
-
"--color-accent": theme.colors.accent.primary,
|
|
74
|
-
"--color-accent-primary": theme.colors.accent.primary,
|
|
75
|
-
"--color-accent-secondary": theme.colors.accent.secondary,
|
|
76
|
-
"--color-accent-alpha": theme.colors.accent.alpha,
|
|
77
|
-
"--color-accent-text": theme.colors.accent.text,
|
|
78
|
-
|
|
79
|
-
"--color-info": theme.colors.info.primary,
|
|
80
|
-
"--color-info-primary": theme.colors.info.primary,
|
|
81
|
-
"--color-info-secondary": theme.colors.info.secondary,
|
|
82
|
-
"--color-info-alpha": theme.colors.info.alpha,
|
|
83
|
-
"--color-info-text": theme.colors.info.text,
|
|
84
|
-
|
|
85
|
-
"--color-success": theme.colors.success.primary,
|
|
86
|
-
"--color-success-primary": theme.colors.success.primary,
|
|
87
|
-
"--color-success-secondary": theme.colors.success.secondary,
|
|
88
|
-
"--color-success-alpha": theme.colors.success.alpha,
|
|
89
|
-
"--color-success-text": theme.colors.success.text,
|
|
90
|
-
|
|
91
|
-
"--color-warning": theme.colors.warning.primary,
|
|
92
|
-
"--color-warning-primary": theme.colors.warning.primary,
|
|
93
|
-
"--color-warning-secondary": theme.colors.warning.secondary,
|
|
94
|
-
"--color-warning-alpha": theme.colors.warning.alpha,
|
|
95
|
-
"--color-warning-text": theme.colors.warning.text,
|
|
96
|
-
|
|
97
|
-
"--color-danger": theme.colors.danger.primary,
|
|
98
|
-
"--color-danger-primary": theme.colors.danger.primary,
|
|
99
|
-
"--color-danger-secondary": theme.colors.danger.secondary,
|
|
100
|
-
"--color-danger-alpha": theme.colors.danger.alpha,
|
|
101
|
-
"--color-danger-text": theme.colors.danger.text,
|
|
102
|
-
...shadows,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export default ThemeCssVars
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import * as React from "react"
|
|
2
|
-
import { ThemeOptions } from "./types"
|
|
3
|
-
import Tag from "../Tag"
|
|
4
|
-
import { TagComponentType, TagProps } from "../Tag/types"
|
|
5
|
-
import { BreakpointProvider } from "../breakpoint"
|
|
6
|
-
import { ThemeContex, ThemeFactory } from "./core"
|
|
7
|
-
import ThemeCssVars from "./ThemeCssVars"
|
|
8
|
-
import { css } from "../css"
|
|
9
|
-
|
|
10
|
-
export type ThemeProviderProps<T extends TagComponentType = 'div'> = TagProps<T> & {
|
|
11
|
-
theme: string;
|
|
12
|
-
resetCss?: boolean;
|
|
13
|
-
scrollbarCss?: boolean;
|
|
14
|
-
isRootProvider?: boolean;
|
|
15
|
-
renderIsRoot?: React.ReactElement;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const ThemeProvider = ({ children, theme, resetCss, scrollbarCss, isRootProvider, renderIsRoot, ...props }: ThemeProviderProps) => {
|
|
19
|
-
const THEME = ThemeFactory.get(theme) as ThemeOptions
|
|
20
|
-
if (!THEME) throw new Error(`Invalid theme name provided: ${theme}`)
|
|
21
|
-
resetCss ??= true
|
|
22
|
-
scrollbarCss ??= true
|
|
23
|
-
|
|
24
|
-
React.useMemo(() => {
|
|
25
|
-
if (!!Object.keys(THEME.globalStyle).length) {
|
|
26
|
-
css({
|
|
27
|
-
"@global": THEME.globalStyle
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
css({
|
|
32
|
-
"@global": {
|
|
33
|
-
[`.xui-${theme}-theme-root`]: ThemeCssVars(THEME)
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
if (scrollbarCss && typeof document !== 'undefined') {
|
|
38
|
-
let thumbSize = 10
|
|
39
|
-
let thumbColor = THEME.colors.divider
|
|
40
|
-
let trackColor = THEME.colors.background.secondary
|
|
41
|
-
css({
|
|
42
|
-
"@global": {
|
|
43
|
-
"*": {
|
|
44
|
-
scrollbarWidth: "thin",
|
|
45
|
-
scrollbarColor: `${thumbColor} ${trackColor}`,
|
|
46
|
-
},
|
|
47
|
-
"::-webkit-scrollbar": {
|
|
48
|
-
width: thumbSize,
|
|
49
|
-
height: thumbSize,
|
|
50
|
-
},
|
|
51
|
-
"::-webkit-scrollbar-thumb": {
|
|
52
|
-
backgroundColor: thumbColor,
|
|
53
|
-
borderRadius: "5px",
|
|
54
|
-
border: "2px solid #f4f4f4",
|
|
55
|
-
},
|
|
56
|
-
"::-webkit-scrollbar-thumb:hover": {
|
|
57
|
-
backgroundColor: thumbColor,
|
|
58
|
-
},
|
|
59
|
-
"::-webkit-scrollbar-track": {
|
|
60
|
-
backgroundColor: trackColor,
|
|
61
|
-
borderRadius: "5px",
|
|
62
|
-
},
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
resetCss && css({
|
|
68
|
-
"@global": {
|
|
69
|
-
"*": {
|
|
70
|
-
m: 0,
|
|
71
|
-
p: 0,
|
|
72
|
-
outline: "none",
|
|
73
|
-
boxSizing: "border-box",
|
|
74
|
-
verticalAlign: "baseline",
|
|
75
|
-
},
|
|
76
|
-
"html, body": {
|
|
77
|
-
minHeight: "100%",
|
|
78
|
-
"-webkit-font-smoothing": "antialiased"
|
|
79
|
-
} as any,
|
|
80
|
-
"img, picture, video, canvas, svg": {
|
|
81
|
-
maxWidth: "100%",
|
|
82
|
-
display: "block"
|
|
83
|
-
},
|
|
84
|
-
"input, button, textarea, select": {
|
|
85
|
-
font: "inherit"
|
|
86
|
-
},
|
|
87
|
-
"table": {
|
|
88
|
-
borderCollapse: "collapse",
|
|
89
|
-
borderSpacing: 0
|
|
90
|
-
},
|
|
91
|
-
"ol, ul": {
|
|
92
|
-
listStyle: "none"
|
|
93
|
-
},
|
|
94
|
-
"a": {
|
|
95
|
-
display: "inline-block"
|
|
96
|
-
},
|
|
97
|
-
"p, h1, h2, h3, h4, h5, h6": {
|
|
98
|
-
overflowWrap: "break-word",
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
}, [theme])
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<ThemeContex.Provider value={theme}>
|
|
106
|
-
{
|
|
107
|
-
isRootProvider ? <BreakpointProvider>
|
|
108
|
-
<Tag
|
|
109
|
-
minHeight="100%"
|
|
110
|
-
bgcolor={THEME.colors.background.primary}
|
|
111
|
-
fontFamily={THEME.typography.fontFamily}
|
|
112
|
-
fontSize={THEME.typography.text.fontSize}
|
|
113
|
-
fontWeight={THEME.typography.text.fontWeight}
|
|
114
|
-
lineHeight={THEME.typography.text.lineHeight}
|
|
115
|
-
{...props}
|
|
116
|
-
baseClass={`${theme}-theme-root`}
|
|
117
|
-
direction={THEME.rtl ? "rtl" : "ltr"}
|
|
118
|
-
>
|
|
119
|
-
{children}
|
|
120
|
-
{renderIsRoot}
|
|
121
|
-
</Tag>
|
|
122
|
-
</BreakpointProvider> : <Tag
|
|
123
|
-
minHeight="100%"
|
|
124
|
-
bgcolor={THEME.colors.background.primary}
|
|
125
|
-
fontFamily={THEME.typography.fontFamily}
|
|
126
|
-
fontSize={THEME.typography.text.fontSize}
|
|
127
|
-
fontWeight={THEME.typography.text.fontWeight}
|
|
128
|
-
lineHeight={THEME.typography.text.lineHeight}
|
|
129
|
-
{...props}
|
|
130
|
-
baseClass={`${theme}-theme-root`}
|
|
131
|
-
direction={THEME.rtl ? "rtl" : "ltr"}
|
|
132
|
-
>
|
|
133
|
-
{children}
|
|
134
|
-
</Tag>
|
|
135
|
-
}
|
|
136
|
-
</ThemeContex.Provider>
|
|
137
|
-
)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export default ThemeProvider
|
package/src/theme/core.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
import { ObjectType, ThemeOptions } from "./types"
|
|
3
|
-
|
|
4
|
-
export const ThemeFactory = new Map<string, ThemeOptions>()
|
|
5
|
-
export const ThemeContex = React.createContext("light")
|
|
6
|
-
export const getTheme = (theme: string) => ThemeFactory.get(theme)
|
|
7
|
-
export const useTheme = (): ThemeOptions => ThemeFactory.get(React.useContext(ThemeContex)) as any
|
|
8
|
-
|
|
9
|
-
export const mergeObject = (a: ObjectType, b: ObjectType) => {
|
|
10
|
-
a = { ...a }
|
|
11
|
-
b = { ...b }
|
|
12
|
-
for (const key in b) {
|
|
13
|
-
const v = (b as any)[key]
|
|
14
|
-
if (typeof v === 'object' && !Array.isArray(v) && !React.isValidElement(v)) {
|
|
15
|
-
a[key] = mergeObject(a[key], b[key])
|
|
16
|
-
} else {
|
|
17
|
-
a[key] = v
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return a
|
|
21
|
-
}
|
package/src/theme/createColor.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ThemeOptions, ThemeColor } from "./types"
|
|
2
|
-
import { alpha } from "../css"
|
|
3
|
-
|
|
4
|
-
const createColor = (theme: ThemeOptions, name: keyof ThemeColor) => {
|
|
5
|
-
let color = theme.colors[name]
|
|
6
|
-
let { primary, secondary } = color as any
|
|
7
|
-
let text = (color as any).text || theme.colors.text.primary
|
|
8
|
-
let _alpha = alpha(primary, .1)
|
|
9
|
-
|
|
10
|
-
const isBag = (a: any, b: any) => name === "background" ? a : b
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
alpha: _alpha,
|
|
14
|
-
template: {
|
|
15
|
-
outline: {
|
|
16
|
-
bgcolor: "transparent",
|
|
17
|
-
color: isBag(text, primary),
|
|
18
|
-
border: 1,
|
|
19
|
-
borderColor: isBag("divider", alpha(primary, .4)),
|
|
20
|
-
hover: {
|
|
21
|
-
color: isBag(text, primary),
|
|
22
|
-
borderColor: isBag("divider", alpha(primary, .8)),
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
fill: {
|
|
26
|
-
bgcolor: isBag(secondary, primary),
|
|
27
|
-
color: text,
|
|
28
|
-
hover: {
|
|
29
|
-
bgcolor: isBag(alpha(secondary, .6), secondary),
|
|
30
|
-
color: text,
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
text: {
|
|
34
|
-
bgcolor: "transparent",
|
|
35
|
-
color: isBag(text, primary),
|
|
36
|
-
hover: {
|
|
37
|
-
bgcolor: isBag(alpha(secondary, .6), alpha(primary, .1)),
|
|
38
|
-
color: isBag(text, primary),
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
alpha: {
|
|
42
|
-
bgcolor: isBag(alpha(secondary, .5), alpha(primary, .1)),
|
|
43
|
-
color: isBag(text, primary),
|
|
44
|
-
hover: {
|
|
45
|
-
bgcolor: isBag(alpha(secondary, .8), alpha(primary, .15)),
|
|
46
|
-
color: isBag(text, primary),
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export default createColor
|
package/src/theme/createTheme.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ThemeOptions, ThemeOptionInput } from "./types"
|
|
2
|
-
import defaultThemeOption, { darkColorPallete } from './ThemeDefaultOptions'
|
|
3
|
-
import { mergeObject, ThemeFactory } from "./core"
|
|
4
|
-
import createColor from "./createColor"
|
|
5
|
-
import { breakpoints } from "../css"
|
|
6
|
-
|
|
7
|
-
export const createTheme = (name: string, options: ThemeOptionInput, darkMode?: boolean): ThemeOptions => {
|
|
8
|
-
if (!ThemeFactory.has(name)) {
|
|
9
|
-
let theme: any = mergeObject(defaultThemeOption, {
|
|
10
|
-
...(darkMode ? darkColorPallete : {}),
|
|
11
|
-
...options,
|
|
12
|
-
name,
|
|
13
|
-
breakpoints: breakpoints
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
theme = mergeObject(theme, {
|
|
17
|
-
colors: {
|
|
18
|
-
background: createColor(theme, "background"),
|
|
19
|
-
brand: createColor(theme, "brand"),
|
|
20
|
-
accent: createColor(theme, "accent"),
|
|
21
|
-
info: createColor(theme, "info"),
|
|
22
|
-
success: createColor(theme, "success"),
|
|
23
|
-
warning: createColor(theme, "warning"),
|
|
24
|
-
danger: createColor(theme, "danger")
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
ThemeFactory.set(name, theme)
|
|
28
|
-
} else {
|
|
29
|
-
throw new Error(`theme "${name}" already exists!`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return ThemeFactory.get(name) as ThemeOptions
|
|
33
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { createBucket } from "react-state-bucket"
|
|
2
|
-
import { getTheme } from "./core"
|
|
3
|
-
|
|
4
|
-
const createThemeSwitcher = (defaultTheme: string, store?: "session" | "local") => {
|
|
5
|
-
const useThemeState = createBucket({ name: defaultTheme }, { store })
|
|
6
|
-
const useThemeSwitcher = () => {
|
|
7
|
-
const state = useThemeState()
|
|
8
|
-
return {
|
|
9
|
-
name: state.get("name"),
|
|
10
|
-
theme: getTheme(state.get("name")),
|
|
11
|
-
change: (theme: string) => state.set("name", theme)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return useThemeSwitcher
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export default createThemeSwitcher
|
package/src/theme/index.tsx
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { lightColorPallete, darkColorPallete } from './ThemeDefaultOptions'
|
|
2
|
-
import { createTheme } from "./createTheme"
|
|
3
|
-
import ThemeProvider from './ThemeProvider'
|
|
4
|
-
import createThemeSwitcher from './createThemeSwitcher'
|
|
5
|
-
import { getTheme, useTheme } from './core'
|
|
6
|
-
export type { ThemeProviderProps } from './ThemeProvider'
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
ThemeProvider,
|
|
10
|
-
createThemeSwitcher,
|
|
11
|
-
getTheme,
|
|
12
|
-
useTheme
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
createTheme("light", { colors: lightColorPallete })
|
|
16
|
-
createTheme("dark", { colors: darkColorPallete })
|
|
17
|
-
|