@cronocode/react-box 3.0.1 → 3.0.2

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/README.md CHANGED
@@ -6,7 +6,7 @@ This is a react base component which will reduce considerably necessity to write
6
6
 
7
7
  1. Installation
8
8
 
9
- ```
9
+ ```bash
10
10
  npm install @cronocode/react-box
11
11
  ```
12
12
 
@@ -18,7 +18,7 @@ Sizes is equal to `1/4rem`
18
18
 
19
19
  In the example below is creating a box with `maring: 0.5rem` and `padding: 1.75rem`
20
20
 
21
- ```
21
+ ```JS
22
22
  import Box from "@cronocode/react-box";
23
23
 
24
24
  export default function Component(props: Props) {
@@ -36,7 +36,7 @@ export default function Component(props: Props) {
36
36
 
37
37
  - **Box** - base component with a tons of props
38
38
 
39
- ```
39
+ ```JS
40
40
  import Box from "@cronocode/react-box";
41
41
  ```
42
42
 
@@ -46,72 +46,83 @@ import Box from "@cronocode/react-box";
46
46
 
47
47
  - **Flex** - this is a `Box` component with `display: flex` style
48
48
 
49
- ```
49
+ ```JS
50
50
  import Flex from "@cronocode/react-box/components/flex";
51
51
  ```
52
52
 
53
53
  - **Button** - this is a `Box` component with html tag `button` and `onClick` prop
54
54
 
55
- ```
55
+ ```JS
56
56
  import Button from "@cronocode/react-box/components/button";
57
57
  ```
58
58
 
59
59
  - **Textbox** - this is a `Box` component with html tag `input`
60
60
 
61
- ```
61
+ ```JS
62
62
  import Textbox from "@cronocode/react-box/components/textbox";
63
63
  ```
64
64
 
65
65
  - **Tooltip** - this is useful when you need a position absolute and the parent has overflow hidden.
66
66
 
67
- ```
67
+ ```JS
68
68
  import Tooltip from "@cronocode/react-box/components/tooltip";
69
69
  ```
70
70
 
71
71
  ## Extend props
72
72
 
73
- 1. It is possible to extend some props like `color`, `background`, `backgroundImage` and `shadow`
73
+ It is possible to add your own props to define your custom styles.
74
+ You need to do a few steps.
74
75
 
75
- ```JS
76
- function themePlugin() {
77
- return {
78
- name: 'themePlugin',
79
- configResolved() {
80
- const result = Theme.setupAugmentedProps({
81
- colors: {
82
- primary: '#445566'
83
- },
84
- backgroundImages: {
85
- gradient: 'linear-gradient(to right, #77A1D3 0%, #79CBCA 51%, #77A1D3 100%)'
86
- },
87
- shadows: {
88
- 1: '0 4px 10px rgb(224 224 224 / 52%)',
89
- }
90
- });
91
-
92
- fs.writeFileSync('./src/box-theme.generated.css', result.variables);
93
- fs.writeFileSync('./src/box.generated.d.ts', result.boxDts);
94
- },
95
- }
96
- }
97
-
98
- ```
99
-
100
- 2. Add this plugin to your build tool
101
-
102
- Vitejs
76
+ 1. In a project root file you need to define your extends
103
77
 
104
78
  ```JS
105
- // https://vitejs.dev/config/
106
- export default defineConfig({
107
- plugins: [..., themePlugin()],
108
- })
79
+ import Box from "@cronocode/react-box";
80
+
81
+ export const { extendedProps, extendedPropTypes } = Box.extend(
82
+ // css variables
83
+ {
84
+ dark: '#123123',
85
+ light: '#ededed',
86
+ cssVarName: 'cssVarValue',
87
+ myShadow: '10px 5px 5px red',
88
+ myGradient1: 'linear-gradient(#e66465, #9198e5)',
89
+ myGradient2: 'linear-gradient(black, white)',
90
+ },
91
+ // new custom props
92
+ {
93
+ background: [
94
+ {
95
+ values: ['myGradient1', 'myGradient2'] as const,
96
+ valueFormat: (value: string) => `var(--background${value})`,
97
+ },
98
+ ],
99
+ },
100
+ // extend values for existing props
101
+ {
102
+ color: [
103
+ {
104
+ values: ['dark', 'light'],
105
+ valueFormat: (value, useVariable) => useVariable(value),
106
+ },
107
+ ],
108
+ }
109
+ );
109
110
  ```
110
111
 
111
- 3. Include `box-theme.generated.css` in your root file
112
+ 2. Now you have to add typings to the Box in order to have intellisense for you new props and value.
113
+ You need to create a `box.d.ts`
112
114
 
113
115
  ```JS
114
- import './box-theme.generated.css';
116
+ import '@cronocode/react-box';
117
+ import { ExtractBoxStyles } from '@cronocode/react-box/types';
118
+ import { extendedProps, extendedPropTypes } from './path-to-your-b0x-extends-declaration';
119
+
120
+ declare module '@cronocode/react-box/types' {
121
+ namespace Augmented {
122
+ interface BoxProps extends ExtractBoxStyles<typeof extendedProps> {}
123
+ interface BoxPropTypes extends ExtractBoxStyles<typeof extendedPropTypes> {}
124
+ }
125
+ }
115
126
  ```
116
127
 
117
128
  ## Theme for components
@@ -1,6 +1,8 @@
1
1
  import { BoxStyle } from './coreTypes';
2
2
  declare namespace BoxExtends {
3
- function extend<TProps extends Record<string, BoxStyle[]>>(variables: Record<string, string>, props: TProps): TProps;
4
- function getVariables(): string;
3
+ function extend<TProps extends Record<string, BoxStyle[]>, TPropTypes extends Record<string, BoxStyle[]>>(variables: Record<string, string>, extendedProps: TProps, extendedPropTypes: TPropTypes): {
4
+ extendedProps: TProps;
5
+ extendedPropTypes: TPropTypes;
6
+ };
5
7
  }
6
8
  export default BoxExtends;
@@ -1,4 +1,5 @@
1
1
  import { BoxStylesFormatters } from './boxStylesFormatters';
2
+ import { default as Variables } from './variables';
2
3
  export declare const cssStyles: {
3
4
  /** The appearance CSS property is used to display UI elements with platform-specific styling, based on the operating system's theme. */
4
5
  appearance: {
@@ -642,7 +643,7 @@ export declare const cssStyles: {
642
643
  valueFormat?: undefined;
643
644
  })[];
644
645
  /** The grid-column CSS shorthand property specifies a grid item's size and location within a grid column by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-start and inline-end edge of its grid area. */
645
- gridColumn: ({
646
+ colSpan: ({
646
647
  styleName: string;
647
648
  values: number;
648
649
  valueFormat: (value: number) => string;
@@ -681,6 +682,25 @@ export declare const cssStyles: {
681
682
  styleName: string;
682
683
  values: number;
683
684
  }[];
685
+ color: {
686
+ values: Variables.ColorType[];
687
+ valueFormat: (value: string, useVariable: (name: string) => string) => string;
688
+ }[];
689
+ bgColor: {
690
+ values: Variables.ColorType[];
691
+ valueFormat: (value: string, useVariable: (name: string) => string) => string;
692
+ styleName: string;
693
+ }[];
694
+ borderColor: {
695
+ values: Variables.ColorType[];
696
+ valueFormat: (value: string, useVariable: (name: string) => string) => string;
697
+ styleName: string;
698
+ }[];
699
+ outlineColor: {
700
+ values: Variables.ColorType[];
701
+ valueFormat: (value: string, useVariable: (name: string) => string) => string;
702
+ styleName: string;
703
+ }[];
684
704
  };
685
705
  export declare const pseudo1: {
686
706
  hover: string;
@@ -1,10 +1,9 @@
1
- export type ArrayType<T> = T extends (infer U)[] ? U : T;
2
1
  export type BoxStylesType<T> = T extends ReadonlyArray<infer U> ? T[number] : T;
3
2
  export type ExtractElementType<T> = T extends React.DetailedHTMLProps<React.HTMLAttributes<infer E>, infer E> ? E : T extends React.SVGProps<infer E> ? E : never;
4
3
  export type ExtractElementFromTag<T extends keyof React.JSX.IntrinsicElements> = ExtractElementType<React.JSX.IntrinsicElements[T]>;
5
4
  interface BoxStyleArrayString {
6
5
  values: ReadonlyArray<string>;
7
- valueFormat?: (value: string) => string;
6
+ valueFormat?: (value: string, useVariable: (name: string) => string) => string;
8
7
  }
9
8
  interface BoxStyleArrayBoolean {
10
9
  values: ReadonlyArray<boolean>;
package/core/theme.d.ts CHANGED
@@ -4,6 +4,9 @@ export interface ThemeComponentStyles {
4
4
  themes?: {
5
5
  [name: string]: BoxThemeStyles;
6
6
  };
7
+ children?: {
8
+ [name: string]: ThemeComponentStyles;
9
+ };
7
10
  }
8
11
  export interface ThemeSetup {
9
12
  components?: {
@@ -15,6 +18,7 @@ export interface ThemeSetup {
15
18
  checkbox?: ThemeComponentStyles;
16
19
  radioButton?: ThemeComponentStyles;
17
20
  label?: ThemeComponentStyles;
21
+ dropdown?: ThemeComponentStyles;
18
22
  }
19
23
  declare namespace Theme {
20
24
  function setup(styles: ThemeSetup): void;
@@ -0,0 +1,256 @@
1
+ declare namespace Variables {
2
+ const colors: {
3
+ inherit: string;
4
+ current: string;
5
+ transparent: string;
6
+ black: string;
7
+ white: string;
8
+ 'slate-50': string;
9
+ 'slate-100': string;
10
+ 'slate-200': string;
11
+ 'slate-300': string;
12
+ 'slate-400': string;
13
+ 'slate-500': string;
14
+ 'slate-600': string;
15
+ 'slate-700': string;
16
+ 'slate-800': string;
17
+ 'slate-900': string;
18
+ 'slate-950': string;
19
+ 'gray-50': string;
20
+ 'gray-100': string;
21
+ 'gray-200': string;
22
+ 'gray-300': string;
23
+ 'gray-400': string;
24
+ 'gray-500': string;
25
+ 'gray-600': string;
26
+ 'gray-700': string;
27
+ 'gray-800': string;
28
+ 'gray-900': string;
29
+ 'gray-950': string;
30
+ 'zinc-50': string;
31
+ 'zinc-100': string;
32
+ 'zinc-200': string;
33
+ 'zinc-300': string;
34
+ 'zinc-400': string;
35
+ 'zinc-500': string;
36
+ 'zinc-600': string;
37
+ 'zinc-700': string;
38
+ 'zinc-800': string;
39
+ 'zinc-900': string;
40
+ 'zinc-950': string;
41
+ 'neutral-50': string;
42
+ 'neutral-100': string;
43
+ 'neutral-200': string;
44
+ 'neutral-300': string;
45
+ 'neutral-400': string;
46
+ 'neutral-500': string;
47
+ 'neutral-600': string;
48
+ 'neutral-700': string;
49
+ 'neutral-800': string;
50
+ 'neutral-900': string;
51
+ 'neutral-950': string;
52
+ 'stone-50': string;
53
+ 'stone-100': string;
54
+ 'stone-200': string;
55
+ 'stone-300': string;
56
+ 'stone-400': string;
57
+ 'stone-500': string;
58
+ 'stone-600': string;
59
+ 'stone-700': string;
60
+ 'stone-800': string;
61
+ 'stone-900': string;
62
+ 'stone-950': string;
63
+ 'red-50': string;
64
+ 'red-100': string;
65
+ 'red-200': string;
66
+ 'red-300': string;
67
+ 'red-400': string;
68
+ 'red-500': string;
69
+ 'red-600': string;
70
+ 'red-700': string;
71
+ 'red-800': string;
72
+ 'red-900': string;
73
+ 'red-950': string;
74
+ 'orange-50': string;
75
+ 'orange-100': string;
76
+ 'orange-200': string;
77
+ 'orange-300': string;
78
+ 'orange-400': string;
79
+ 'orange-500': string;
80
+ 'orange-600': string;
81
+ 'orange-700': string;
82
+ 'orange-800': string;
83
+ 'orange-900': string;
84
+ 'orange-950': string;
85
+ 'amber-50': string;
86
+ 'amber-100': string;
87
+ 'amber-200': string;
88
+ 'amber-300': string;
89
+ 'amber-400': string;
90
+ 'amber-500': string;
91
+ 'amber-600': string;
92
+ 'amber-700': string;
93
+ 'amber-800': string;
94
+ 'amber-900': string;
95
+ 'amber-950': string;
96
+ 'yellow-50': string;
97
+ 'yellow-100': string;
98
+ 'yellow-200': string;
99
+ 'yellow-300': string;
100
+ 'yellow-400': string;
101
+ 'yellow-500': string;
102
+ 'yellow-600': string;
103
+ 'yellow-700': string;
104
+ 'yellow-800': string;
105
+ 'yellow-900': string;
106
+ 'yellow-950': string;
107
+ 'lime-50': string;
108
+ 'lime-100': string;
109
+ 'lime-200': string;
110
+ 'lime-300': string;
111
+ 'lime-400': string;
112
+ 'lime-500': string;
113
+ 'lime-600': string;
114
+ 'lime-700': string;
115
+ 'lime-800': string;
116
+ 'lime-900': string;
117
+ 'lime-950': string;
118
+ 'green-50': string;
119
+ 'green-100': string;
120
+ 'green-200': string;
121
+ 'green-300': string;
122
+ 'green-400': string;
123
+ 'green-500': string;
124
+ 'green-600': string;
125
+ 'green-700': string;
126
+ 'green-800': string;
127
+ 'green-900': string;
128
+ 'green-950': string;
129
+ 'emerald-50': string;
130
+ 'emerald-100': string;
131
+ 'emerald-200': string;
132
+ 'emerald-300': string;
133
+ 'emerald-400': string;
134
+ 'emerald-500': string;
135
+ 'emerald-600': string;
136
+ 'emerald-700': string;
137
+ 'emerald-800': string;
138
+ 'emerald-900': string;
139
+ 'emerald-950': string;
140
+ 'teal-50': string;
141
+ 'teal-100': string;
142
+ 'teal-200': string;
143
+ 'teal-300': string;
144
+ 'teal-400': string;
145
+ 'teal-500': string;
146
+ 'teal-600': string;
147
+ 'teal-700': string;
148
+ 'teal-800': string;
149
+ 'teal-900': string;
150
+ 'teal-950': string;
151
+ 'cyan-50': string;
152
+ 'cyan-100': string;
153
+ 'cyan-200': string;
154
+ 'cyan-300': string;
155
+ 'cyan-400': string;
156
+ 'cyan-500': string;
157
+ 'cyan-600': string;
158
+ 'cyan-700': string;
159
+ 'cyan-800': string;
160
+ 'cyan-900': string;
161
+ 'cyan-950': string;
162
+ 'sky-50': string;
163
+ 'sky-100': string;
164
+ 'sky-200': string;
165
+ 'sky-300': string;
166
+ 'sky-400': string;
167
+ 'sky-500': string;
168
+ 'sky-600': string;
169
+ 'sky-700': string;
170
+ 'sky-800': string;
171
+ 'sky-900': string;
172
+ 'sky-950': string;
173
+ 'blue-50': string;
174
+ 'blue-100': string;
175
+ 'blue-200': string;
176
+ 'blue-300': string;
177
+ 'blue-400': string;
178
+ 'blue-500': string;
179
+ 'blue-600': string;
180
+ 'blue-700': string;
181
+ 'blue-800': string;
182
+ 'blue-900': string;
183
+ 'blue-950': string;
184
+ 'indigo-50': string;
185
+ 'indigo-100': string;
186
+ 'indigo-200': string;
187
+ 'indigo-300': string;
188
+ 'indigo-400': string;
189
+ 'indigo-500': string;
190
+ 'indigo-600': string;
191
+ 'indigo-700': string;
192
+ 'indigo-800': string;
193
+ 'indigo-900': string;
194
+ 'indigo-950': string;
195
+ 'violet-50': string;
196
+ 'violet-100': string;
197
+ 'violet-200': string;
198
+ 'violet-300': string;
199
+ 'violet-400': string;
200
+ 'violet-500': string;
201
+ 'violet-600': string;
202
+ 'violet-700': string;
203
+ 'violet-800': string;
204
+ 'violet-900': string;
205
+ 'violet-950': string;
206
+ 'purple-50': string;
207
+ 'purple-100': string;
208
+ 'purple-200': string;
209
+ 'purple-300': string;
210
+ 'purple-400': string;
211
+ 'purple-500': string;
212
+ 'purple-600': string;
213
+ 'purple-700': string;
214
+ 'purple-800': string;
215
+ 'purple-900': string;
216
+ 'purple-950': string;
217
+ 'fuchsia-50': string;
218
+ 'fuchsia-100': string;
219
+ 'fuchsia-200': string;
220
+ 'fuchsia-300': string;
221
+ 'fuchsia-400': string;
222
+ 'fuchsia-500': string;
223
+ 'fuchsia-600': string;
224
+ 'fuchsia-700': string;
225
+ 'fuchsia-800': string;
226
+ 'fuchsia-900': string;
227
+ 'fuchsia-950': string;
228
+ 'pink-50': string;
229
+ 'pink-100': string;
230
+ 'pink-200': string;
231
+ 'pink-300': string;
232
+ 'pink-400': string;
233
+ 'pink-500': string;
234
+ 'pink-600': string;
235
+ 'pink-700': string;
236
+ 'pink-800': string;
237
+ 'pink-900': string;
238
+ 'pink-950': string;
239
+ 'rose-50': string;
240
+ 'rose-100': string;
241
+ 'rose-200': string;
242
+ 'rose-300': string;
243
+ 'rose-400': string;
244
+ 'rose-500': string;
245
+ 'rose-600': string;
246
+ 'rose-700': string;
247
+ 'rose-800': string;
248
+ 'rose-900': string;
249
+ 'rose-950': string;
250
+ };
251
+ type ColorType = keyof typeof colors;
252
+ function useVariable(name: string): string;
253
+ function generateVariables(): string;
254
+ function setUserVariables(variables: Record<string, string>): void;
255
+ }
256
+ export default Variables;