@1doc/1ds-react 0.0.1
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 +34 -0
- package/dist/components/Alert/Alert.css +188 -0
- package/dist/components/Alert/Alert.d.ts +65 -0
- package/dist/components/Alert/Alert.js +56 -0
- package/dist/components/Avatar/Avatar.css +88 -0
- package/dist/components/Avatar/Avatar.d.ts +34 -0
- package/dist/components/Avatar/Avatar.js +16 -0
- package/dist/components/Avatar/AvatarGroup.d.ts +12 -0
- package/dist/components/Avatar/AvatarGroup.js +8 -0
- package/dist/components/Badge/Badge.css +155 -0
- package/dist/components/Badge/Badge.d.ts +46 -0
- package/dist/components/Badge/Badge.js +17 -0
- package/dist/components/Button/Button.css +199 -0
- package/dist/components/Button/Button.d.ts +23 -0
- package/dist/components/Button/Button.js +62 -0
- package/dist/components/Checkbox/Checkbox.css +122 -0
- package/dist/components/Checkbox/Checkbox.d.ts +21 -0
- package/dist/components/Checkbox/Checkbox.js +49 -0
- package/dist/components/Divider/Divider.css +81 -0
- package/dist/components/Divider/Divider.d.ts +18 -0
- package/dist/components/Divider/Divider.js +26 -0
- package/dist/components/Grid/Grid.css +154 -0
- package/dist/components/Grid/Grid.d.ts +21 -0
- package/dist/components/Grid/Grid.js +53 -0
- package/dist/components/Icon/Icon.css +41 -0
- package/dist/components/Icon/Icon.d.ts +12 -0
- package/dist/components/Icon/Icon.js +29 -0
- package/dist/components/Input/Input.css +190 -0
- package/dist/components/Input/Input.d.ts +32 -0
- package/dist/components/Input/Input.js +58 -0
- package/dist/components/Link/Link.css +76 -0
- package/dist/components/Link/Link.d.ts +15 -0
- package/dist/components/Link/Link.js +19 -0
- package/dist/components/Logo/Logo.css +32 -0
- package/dist/components/Logo/Logo.d.ts +10 -0
- package/dist/components/Logo/Logo.js +16 -0
- package/dist/components/Modal/Modal.css +155 -0
- package/dist/components/Modal/Modal.d.ts +36 -0
- package/dist/components/Modal/Modal.js +55 -0
- package/dist/components/Radio/Radio.css +114 -0
- package/dist/components/Radio/Radio.d.ts +19 -0
- package/dist/components/Radio/Radio.js +39 -0
- package/dist/components/Select/Select.css +291 -0
- package/dist/components/Select/Select.d.ts +38 -0
- package/dist/components/Select/Select.js +246 -0
- package/dist/components/Spinner/Spinner.css +60 -0
- package/dist/components/Spinner/Spinner.d.ts +16 -0
- package/dist/components/Spinner/Spinner.js +16 -0
- package/dist/components/Switch/Switch.css +127 -0
- package/dist/components/Switch/Switch.d.ts +18 -0
- package/dist/components/Switch/Switch.js +57 -0
- package/dist/components/Tabs/Tab.d.ts +19 -0
- package/dist/components/Tabs/Tab.js +76 -0
- package/dist/components/Tabs/TabContent.d.ts +15 -0
- package/dist/components/Tabs/TabContent.js +11 -0
- package/dist/components/Tabs/Tabs.css +124 -0
- package/dist/components/Tabs/Tabs.d.ts +20 -0
- package/dist/components/Tabs/Tabs.js +14 -0
- package/dist/components/Tabs/TabsContent.d.ts +16 -0
- package/dist/components/Tabs/TabsContent.js +12 -0
- package/dist/components/Tabs/tabs.context.d.ts +2 -0
- package/dist/components/Tabs/tabs.context.js +2 -0
- package/dist/components/Tag/Tag.css +140 -0
- package/dist/components/Tag/Tag.d.ts +63 -0
- package/dist/components/Tag/Tag.js +48 -0
- package/dist/components/Text/Text.css +1213 -0
- package/dist/components/Text/Text.d.ts +70 -0
- package/dist/components/Text/Text.js +89 -0
- package/dist/components/Textarea/Textarea.css +133 -0
- package/dist/components/Textarea/Textarea.d.ts +28 -0
- package/dist/components/Textarea/Textarea.js +72 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +27 -0
- package/dist/utils/theme.d.ts +30 -0
- package/dist/utils/theme.js +106 -0
- package/package.json +26 -0
- package/scripts/postbuild.js +21 -0
- package/src/index.ts +28 -0
- package/src/utils/theme.ts +136 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tipos de temas disponíveis no Design System
|
|
3
|
+
*/
|
|
4
|
+
export type Theme =
|
|
5
|
+
| "1doc"
|
|
6
|
+
| "1ds-red"
|
|
7
|
+
| "1ds-green"
|
|
8
|
+
| "1ds-orange"
|
|
9
|
+
| "1ds-yellow";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Chave do localStorage para armazenar o tema selecionado
|
|
13
|
+
*/
|
|
14
|
+
const THEME_STORAGE_KEY = "umds-theme";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Tema padrão do sistema
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_THEME: Theme = "1doc";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Define o tema ativo no documento
|
|
23
|
+
* @param theme - Nome do tema a ser aplicado
|
|
24
|
+
*/
|
|
25
|
+
export const setTheme = (theme: Theme): void => {
|
|
26
|
+
if (typeof document !== "undefined") {
|
|
27
|
+
document.documentElement.setAttribute("data-theme", theme);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
localStorage.setItem(THEME_STORAGE_KEY, theme);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
// Silenciosamente falha se localStorage não estiver disponível
|
|
33
|
+
console.warn("Failed to save theme to localStorage:", e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Obtém o tema atual, considerando localStorage e preferências do sistema
|
|
40
|
+
* @returns O tema atualmente selecionado
|
|
41
|
+
*/
|
|
42
|
+
export const getTheme = (): Theme => {
|
|
43
|
+
if (typeof window === "undefined") {
|
|
44
|
+
return DEFAULT_THEME;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 1. Tenta buscar do localStorage
|
|
48
|
+
try {
|
|
49
|
+
const stored = localStorage.getItem(THEME_STORAGE_KEY) as Theme | null;
|
|
50
|
+
if (stored && isValidTheme(stored)) {
|
|
51
|
+
return stored;
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.warn("Failed to read theme from localStorage:", e);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 2. Tenta buscar do atributo data-theme do HTML
|
|
58
|
+
const currentTheme = document.documentElement.getAttribute(
|
|
59
|
+
"data-theme",
|
|
60
|
+
) as Theme | null;
|
|
61
|
+
if (currentTheme && isValidTheme(currentTheme)) {
|
|
62
|
+
return currentTheme;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 3. Retorna o tema padrão
|
|
66
|
+
return DEFAULT_THEME;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Inicializa o tema ao carregar a página
|
|
71
|
+
* Deve ser chamado o mais cedo possível para evitar flash de conteúdo
|
|
72
|
+
*/
|
|
73
|
+
export const initTheme = (): void => {
|
|
74
|
+
const theme = getTheme();
|
|
75
|
+
setTheme(theme);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Valida se uma string é um tema válido
|
|
80
|
+
* @param theme - String a ser validada
|
|
81
|
+
* @returns true se o tema é válido
|
|
82
|
+
*/
|
|
83
|
+
function isValidTheme(theme: string): theme is Theme {
|
|
84
|
+
const validThemes: Theme[] = [
|
|
85
|
+
"1doc",
|
|
86
|
+
"1ds-red",
|
|
87
|
+
"1ds-green",
|
|
88
|
+
"1ds-orange",
|
|
89
|
+
"1ds-yellow",
|
|
90
|
+
];
|
|
91
|
+
return validThemes.includes(theme as Theme);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Retorna todos os temas disponíveis
|
|
96
|
+
* @returns Array com todos os temas disponíveis
|
|
97
|
+
*/
|
|
98
|
+
export const getAvailableThemes = (): Theme[] => {
|
|
99
|
+
return ["1doc", "1ds-red", "1ds-green", "1ds-orange", "1ds-yellow"];
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Hook para detectar mudanças de tema (útil para frameworks reativos)
|
|
104
|
+
* @param callback - Função a ser executada quando o tema mudar
|
|
105
|
+
* @returns Função para remover o listener
|
|
106
|
+
*/
|
|
107
|
+
export const onThemeChange = (
|
|
108
|
+
callback: (theme: Theme) => void,
|
|
109
|
+
): (() => void) => {
|
|
110
|
+
if (typeof window === "undefined") {
|
|
111
|
+
return () => {};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const observer = new MutationObserver((mutations) => {
|
|
115
|
+
mutations.forEach((mutation) => {
|
|
116
|
+
if (
|
|
117
|
+
mutation.type === "attributes" &&
|
|
118
|
+
mutation.attributeName === "data-theme"
|
|
119
|
+
) {
|
|
120
|
+
const newTheme = document.documentElement.getAttribute(
|
|
121
|
+
"data-theme",
|
|
122
|
+
) as Theme;
|
|
123
|
+
if (newTheme && isValidTheme(newTheme)) {
|
|
124
|
+
callback(newTheme);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
observer.observe(document.documentElement, {
|
|
131
|
+
attributes: true,
|
|
132
|
+
attributeFilter: ["data-theme"],
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return () => observer.disconnect();
|
|
136
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": [
|
|
6
|
+
"DOM",
|
|
7
|
+
"DOM.Iterable",
|
|
8
|
+
"ESNext"
|
|
9
|
+
],
|
|
10
|
+
"allowJs": false,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"esModuleInterop": false,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"module": "ESNext",
|
|
17
|
+
"moduleResolution": "Node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"noEmit": false,
|
|
21
|
+
"jsx": "react-jsx",
|
|
22
|
+
"declaration": true,
|
|
23
|
+
"outDir": "./dist",
|
|
24
|
+
"rootDir": "./src"
|
|
25
|
+
},
|
|
26
|
+
"include": [
|
|
27
|
+
"src"
|
|
28
|
+
]
|
|
29
|
+
}
|