@apia/theme 0.0.9-alpha.0 → 0.1.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/cleanDist.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "cleanDist": 0.006456232710121412
3
+ }
package/dist/index.d.ts CHANGED
@@ -1,50 +1,13 @@
1
- import { Theme, ThemeUICSSObject, ResponsiveStyleValue } from 'theme-ui';
2
1
  import * as theme_ui_jsx_runtime from 'theme-ui/jsx-runtime';
3
- import { FC, ReactNode } from 'react';
4
- import * as _theme_ui_css from '@theme-ui/css';
5
-
6
- declare function useMainTheme(customTheme?: Theme): Theme;
7
-
8
- /**
9
- * Permite crear un componente cuyos estilos pueden ser redefinidos por un
10
- * usuario final.
11
- *
12
- * Esto es así puesto que los estilos definidos serán agregados a un árbol que
13
- * el usuario puede consultar y sobreescribir. De esta manera los estilos
14
- * finales del componente serán aquellos definidos en este método pero
15
- * sobreescritos por los definidos por el usuario si es que existen.
16
- *
17
- * **Importante** Para aplicar la variante, se aplica un box alrededor del
18
- * componente que se está renderizando, con className="variant__holder". En caso
19
- * de que se quisiera evitar este comportamiento, se debe pasar unwraped = true
20
- *
21
- * @param displayName Este parámetro es importante para el debugger de React.
22
- * @param stylesPath La ruta donde se aplicarán los estilos, es importante asegurarse de que esa ruta ya no está siendo utilizada por otro componente.
23
- * @param styles Un objeto de estilos de ThemeUI
24
- * @param Component La definición del componente.
25
- * @returns Un componente reutilizable y exportable que tiene estilos aplicados.
26
- */
27
- declare function makeStyledComponent<T extends object>(displayName: string, stylesPath: string, styles: ThemeUICSSObject, Component: FC<T>, unwraped?: boolean): ((props: T) => theme_ui_jsx_runtime.JSX.Element) & {
28
- displayName: string;
29
- };
30
-
31
- /**
32
- * Esta función permite agregar estilos al tema principal de la aplicación, de
33
- * modo que estén disponibles para cualquier componente que lo requirea.
34
- *
35
- * @example
36
- *
37
- * injectStyles('buttons.myRedButton', {
38
- * variant: 'buttons.primary',
39
- * backgroundColor: 'red',
40
- * })
41
- */
42
- declare function injectStyles(path: string, styles: ThemeUICSSObject): void;
2
+ import * as react from 'react';
3
+ import { ReactNode, FC } from 'react';
4
+ import { Theme, ResponsiveStyleValue, ThemeUICSSObject } from 'theme-ui';
43
5
 
44
6
  interface TThemeProvider {
45
7
  children: ReactNode;
46
8
  customTheme?: Theme;
47
9
  }
10
+ declare const ThemeProviderContext: react.Context<Theme>;
48
11
  declare const ThemeProvider: ({ children, customTheme }: TThemeProvider) => theme_ui_jsx_runtime.JSX.Element;
49
12
 
50
13
  /**
@@ -78,7 +41,7 @@ declare function responsive<T>(values: {
78
41
  * pt: spacing(8)
79
42
  * }
80
43
  */
81
- declare function spacing(index: number): number | false | (number | _theme_ui_css.ThemeUIEmpty)[];
44
+ declare function spacing(index: number): ResponsiveStyleValue<number>;
82
45
  declare const smallButton: {
83
46
  py: number;
84
47
  px: number;
@@ -90,4 +53,281 @@ declare function getVariant(variant: string): {
90
53
  'data-variant': string;
91
54
  };
92
55
 
93
- export { ThemeProvider, focusOutline, getVariant, injectStyles, makeStyledComponent, responsive, smallButton, spacing, useMainTheme };
56
+ interface TGetColorsAndStatesOptions {
57
+ mergeObject?: Record<string, any>;
58
+ states?: {
59
+ active?: boolean;
60
+ checked?: boolean;
61
+ default?: boolean;
62
+ disabled?: boolean;
63
+ focus?: boolean;
64
+ hover?: boolean;
65
+ readonly?: boolean;
66
+ selected?: boolean;
67
+ };
68
+ }
69
+ /**
70
+ * Esta función es útil para devolver los estados calculados por la aplicación
71
+ * dentro del objeto colors de ThemeUI. Si se desea calcular los estados en
72
+ * base a un color, se debe utilizar el método getColorsAndStatesByColor.
73
+ */
74
+ declare function getColorsAndStatesByPath(path: string, options?: TGetColorsAndStatesOptions): Record<string, ThemeUICSSObject>;
75
+
76
+ interface IColorDefinition {
77
+ main: string;
78
+ light?: string;
79
+ dark?: string;
80
+ contrastText?: string;
81
+ }
82
+ interface IActionOpacity {
83
+ light: string;
84
+ dark: string;
85
+ }
86
+ interface TStates {
87
+ active?: boolean;
88
+ checked?: boolean;
89
+ default?: boolean;
90
+ disabled?: boolean;
91
+ focus?: boolean;
92
+ hover?: boolean;
93
+ readonly?: boolean;
94
+ selected?: boolean;
95
+ }
96
+ type TGetColorStateDefinition = Pick<ThemeUICSSObject, 'backgroundColor' | 'borderColor' | 'borderLeftColor' | 'borderRightColor' | 'borderBottomColor' | 'borderTopColor' | 'color'>;
97
+ type TColorStateRetriever = (color: string, state: keyof TStates) => string;
98
+ type TStateRetriever = (definition: Partial<TGetColorStateDefinition>, state: keyof TStates) => TGetColorStateDefinition;
99
+ type TStatesRetriever = (definition: Partial<TGetColorStateDefinition>, states?: TStates) => ThemeUICSSObject;
100
+ interface TActionDefinition<OpacityColor = undefined | string | IActionOpacity> {
101
+ active: OpacityColor;
102
+ activeOpacity: number;
103
+ disabled: OpacityColor;
104
+ disabledOpacity: number;
105
+ focus: OpacityColor;
106
+ focusOpacity: number;
107
+ hover: OpacityColor;
108
+ hoverOpacity: number;
109
+ readonly: OpacityColor;
110
+ readonlyOpacity: number;
111
+ selected: OpacityColor;
112
+ selectedOpacity: number;
113
+ }
114
+ type TColorModifier = (color: string, ratio?: number) => string;
115
+ interface TPalette<ColorDefinition = IColorDefinition, ColorModifier = TColorModifier, ActionDefinition = TActionDefinition> {
116
+ action: ActionDefinition;
117
+ background: {
118
+ default: string;
119
+ overlay: string;
120
+ paper: string;
121
+ };
122
+ border: {
123
+ article: string;
124
+ field: string;
125
+ section: string;
126
+ };
127
+ common: {
128
+ white: string;
129
+ black: string;
130
+ };
131
+ error: ColorDefinition;
132
+ gray?: {
133
+ 100: string;
134
+ 150: string;
135
+ 200: string;
136
+ 250: string;
137
+ 300: string;
138
+ 350: string;
139
+ 400: string;
140
+ 450: string;
141
+ 500: string;
142
+ 550: string;
143
+ 600: string;
144
+ 650: string;
145
+ 700: string;
146
+ 750: string;
147
+ 800: string;
148
+ 850: string;
149
+ 900: string;
150
+ 950: string;
151
+ };
152
+ info: ColorDefinition;
153
+ primary: ColorDefinition;
154
+ secondary: ColorDefinition;
155
+ spacing: (index: number) => ResponsiveStyleValue<number>;
156
+ success: ColorDefinition;
157
+ text: {
158
+ accent: string;
159
+ disabled: string;
160
+ icon: string;
161
+ link: string;
162
+ primary: string;
163
+ secondary: string;
164
+ title: string;
165
+ };
166
+ warning: ColorDefinition;
167
+ lightenRatio?: number;
168
+ darkenRatio?: number;
169
+ /**
170
+ * Acepta un ratio entre 0 y 100
171
+ */
172
+ lightenColor?: ColorModifier;
173
+ /**
174
+ * Acepta un ratio entre 0 y 100
175
+ */
176
+ darkenColor?: ColorModifier;
177
+ getContrastText?: ColorModifier;
178
+ responsive: typeof responsive;
179
+ queryColumnsMultiplier?: number;
180
+ }
181
+ type TBuildStateObject = <T extends Partial<ThemeUICSSObject>>(props: T, state: keyof Required<TStates> | 'checked') => ThemeUICSSObject;
182
+ type TParsedPalette = Required<TPalette<Required<IColorDefinition>, TColorModifier, Required<TActionDefinition<IActionOpacity>>>> & {
183
+ buildStateObject: TBuildStateObject;
184
+ getColor: TColorStateRetriever;
185
+ getOneState: TStateRetriever;
186
+ getStatesForColors: TStatesRetriever;
187
+ getStatesFromDefinition: TStatesRetriever;
188
+ getStatesFromPath: typeof getColorsAndStatesByPath;
189
+ };
190
+ declare global {
191
+ interface Window {
192
+ currentPalette: TParsedPalette;
193
+ customPalette?: TPalette;
194
+ defaultPalette?: TPalette;
195
+ }
196
+ }
197
+
198
+ declare function getPalette(arg?: TPalette | boolean): TParsedPalette;
199
+
200
+ /**
201
+ * Este método está pensado para usarse únicamente dentro de applyStates, si se
202
+ * desea obtener un objeto con las propiedades correspondientes a un estado,
203
+ * utilizar el método getColorStates.
204
+ */
205
+ declare const applyStatesGetColor: TStatesRetriever;
206
+
207
+ /**
208
+ * Este método acepta un objeto con backgroundColor y borderColor y aplica el
209
+ * estado pasado como segundo parámetro de la siguiente manera:
210
+ *
211
+ * Si se pasa backgroundColor, se devuelve un backgroundColor y un color, que
212
+ * corresponden al backgroundColor con el estado aplicado y un color calculado
213
+ * con la función getContrastText.
214
+ *
215
+ * Si se pasa borderColor, se devuelve un nuevo borderColor calculado con el
216
+ * estado aplicado.
217
+ */
218
+ declare const getColorState: TStateRetriever;
219
+
220
+ /**
221
+ * Con este método es posible construir un objeto con las propiedades
222
+ * necesarias para aplicar los colores correspondientes a los estados deseados
223
+ * a partir de la definición provista.
224
+ */
225
+ declare const getColorStates: TStatesRetriever;
226
+
227
+ /**
228
+ * Esta función calcula los colores de los estados a partir de la definición
229
+ * pasada.
230
+ */
231
+ declare function getColorsAndStatesByDefinition(definition: Partial<TGetColorStateDefinition>, options?: TGetColorsAndStatesOptions): ThemeUICSSObject;
232
+
233
+ /**
234
+ * Esta función arma un objeto con los colores que se deben aplicar para
235
+ * garantizar que el resultado sea el esperado, por ejemplo, al aplicar un
236
+ * color a un border. Esto es así ya que en ThemeUI hay situaciones en las que
237
+ * si no se aplican el color de borde a cada uno de los lados, no se aplica el
238
+ * color deseado.
239
+ *
240
+ * Ejemplo de lo antedicho es:
241
+ *
242
+ * borderRight: '1px solid',
243
+ * borderColor: 'red'.
244
+ *
245
+ * En este caso, el borde derecho no será rojo como se espera, ya que la
246
+ * propiedad borderRight aplicará un borderRightColor: 'initial', que solamente
247
+ * puede ser reescrito por borderRightColor: 'red'.
248
+ */
249
+ declare function getColorsByDefinition(definition: Partial<TGetColorStateDefinition>, options?: {
250
+ mergeObject?: Record<string, any>;
251
+ }): TGetColorStateDefinition & Record<string, any>;
252
+
253
+ /**
254
+ * Esta función NO CALCULA ningún color, simplemente devuelve un objeto con las
255
+ * rutas de color con el formato de ThemeUI. Es útil cuando se desea aplicar
256
+ * colores definidos en el objeto colors.
257
+ *
258
+ * Si se desea generar un objeto con los colores a partir de una definición de
259
+ * colores del tipo TGetColorStateDefinition se debe utilizar el método
260
+ * getColorsByDefinition.
261
+ */
262
+ declare function getColorsByPath(path: string, options?: {
263
+ mergeObject?: Record<string, any>;
264
+ }): TGetColorStateDefinition & Record<string, any>;
265
+
266
+ /**
267
+
268
+ * Este método acepta un color y aplica el estado pasado como segundo
269
+
270
+ * parámetro. De esta forma se puede obtener el color correspondiente al estado
271
+
272
+ * calculado automáticamente por la aplicación.
273
+
274
+ */
275
+ declare const getOneColorState: TColorStateRetriever;
276
+
277
+ declare function useMainTheme(customTheme?: Theme): Theme;
278
+
279
+ /**
280
+ * Permite crear un componente cuyos estilos pueden ser redefinidos por un
281
+ * usuario final.
282
+ *
283
+ * Esto es así puesto que los estilos definidos serán agregados a un árbol que
284
+ * el usuario puede consultar y sobreescribir. De esta manera los estilos
285
+ * finales del componente serán aquellos definidos en este método pero
286
+ * sobreescritos por los definidos por el usuario si es que existen.
287
+ *
288
+ * **Importante** Para aplicar la variante, se aplica un box alrededor del
289
+ * componente que se está renderizando, con className="variant__holder". En caso
290
+ * de que se quisiera evitar este comportamiento, se debe pasar unwraped = true
291
+ *
292
+ * @param displayName Este parámetro es importante para el debugger de React.
293
+ * @param stylesPath La ruta donde se aplicarán los estilos, es importante asegurarse de que esa ruta ya no está siendo utilizada por otro componente.
294
+ * @param styles Un objeto de estilos de ThemeUI
295
+ * @param Component La definición del componente.
296
+ * @returns Un componente reutilizable y exportable que tiene estilos aplicados.
297
+ */
298
+ declare function makeStyledComponent<T extends object>(displayName: string, stylesPath: string, styles: ThemeUICSSObject, Component: FC<T>, unwraped?: boolean): ((props: T) => theme_ui_jsx_runtime.JSX.Element) & {
299
+ displayName: string;
300
+ };
301
+
302
+ /**
303
+ * Esta función permite agregar estilos al tema principal de la aplicación, de
304
+ * modo que estén disponibles para cualquier componente que lo requirea.
305
+ *
306
+ * @example
307
+ *
308
+ * injectStyles('buttons.myRedButton', {
309
+ * variant: 'buttons.primary',
310
+ * backgroundColor: 'red',
311
+ * })
312
+ */
313
+ declare function injectStyles(path: string, styles: ThemeUICSSObject): void;
314
+ /**
315
+ * Esta función permite agregar estilos al tema principal de la aplicación, de
316
+ * modo que estén disponibles para cualquier componente que lo requirea.
317
+ *
318
+ * @example
319
+ *
320
+ * injectStyles({
321
+ * layout: {
322
+ * panels: {
323
+ * myPanel: {
324
+ * ...
325
+ * }
326
+ * }
327
+ * }
328
+ * })
329
+ */
330
+ declare function injectStyles(styles: ThemeUICSSObject): void;
331
+
332
+ export { ThemeProvider, ThemeProviderContext, applyStatesGetColor, focusOutline, getColorState, getColorStates, getColorsAndStatesByDefinition, getColorsAndStatesByPath, getColorsByDefinition, getColorsByPath, getOneColorState, getPalette, getVariant, injectStyles, makeStyledComponent, responsive, smallButton, spacing, useMainTheme };
333
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}