@octoguide/mui-ui-toolkit 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/README.md +231 -0
- package/dist/index.d.mts +759 -0
- package/dist/index.d.ts +759 -0
- package/dist/index.js +1762 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1723 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# mui-ui-toolkit
|
|
2
|
+
|
|
3
|
+
A TypeScript component library that extends every MUI component with a
|
|
4
|
+
fully token-driven, multi-theme design system. No hard-coded CSS values
|
|
5
|
+
anywhere — every colour, radius, spacing, shadow, and transition comes
|
|
6
|
+
from a typed token set.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Architecture
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
src/
|
|
14
|
+
├── themes/
|
|
15
|
+
│ ├── tokens.ts # ThemeTokens interface — the single source of truth
|
|
16
|
+
│ ├── registry.ts # Maps theme names → token objects
|
|
17
|
+
│ ├── config.ts # Reads active theme from .env
|
|
18
|
+
│ ├── createMuiTheme.ts # Converts tokens → MUI Theme
|
|
19
|
+
│ ├── theme1/ # "Ocean Blue" — blue primary, sharper corners
|
|
20
|
+
│ │ └── index.ts
|
|
21
|
+
│ └── theme2/ # "Forest Green" — green primary, rounder corners
|
|
22
|
+
│ └── index.ts
|
|
23
|
+
├── types/
|
|
24
|
+
│ └── mui.d.ts # Augments MUI Theme with `theme.tokens`
|
|
25
|
+
├── components/
|
|
26
|
+
│ ├── Button/
|
|
27
|
+
│ ├── Card/
|
|
28
|
+
│ └── TextField/
|
|
29
|
+
├── ThemeProvider.tsx # Drop-in provider for consuming apps
|
|
30
|
+
└── index.ts # Public API
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Selecting a theme
|
|
36
|
+
|
|
37
|
+
In your app's `.env` file, set the theme via an environment variable.
|
|
38
|
+
The variable name depends on your build tool:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Vite
|
|
42
|
+
VITE_THEME=theme2
|
|
43
|
+
|
|
44
|
+
# Create React App
|
|
45
|
+
REACT_APP_THEME=theme2
|
|
46
|
+
|
|
47
|
+
# Next.js
|
|
48
|
+
NEXT_PUBLIC_THEME=theme2
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Copy `.env.example` to `.env` and uncomment the right line.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Basic usage
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
// main.tsx (or _app.tsx, layout.tsx, etc.)
|
|
59
|
+
import { ToolkitThemeProvider } from '@mui-ui-toolkit/core';
|
|
60
|
+
|
|
61
|
+
export default function Root() {
|
|
62
|
+
return (
|
|
63
|
+
<ToolkitThemeProvider>
|
|
64
|
+
{' '}
|
|
65
|
+
{/* reads VITE_THEME from .env */}
|
|
66
|
+
<App />
|
|
67
|
+
</ToolkitThemeProvider>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Override the theme at runtime (e.g. user preference)
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
<ToolkitThemeProvider theme="theme1">
|
|
76
|
+
<App />
|
|
77
|
+
</ToolkitThemeProvider>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## How the token system works
|
|
83
|
+
|
|
84
|
+
Every theme implements the `ThemeTokens` interface (`src/themes/tokens.ts`).
|
|
85
|
+
TypeScript will fail to compile if a theme is missing any token, guaranteeing
|
|
86
|
+
complete coverage.
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
ThemeTokens
|
|
90
|
+
├── colors.* primary, secondary, background, text, divider, …
|
|
91
|
+
├── typography.* fontFamily, fontSize*, fontWeight*, lineHeight*, …
|
|
92
|
+
├── spacing.* unit, xs, sm, md, lg, xl, xxl
|
|
93
|
+
├── borderRadius.* none, xs, sm, md, lg, xl, full
|
|
94
|
+
├── shadows.* none, xs, sm, md, lg, xl
|
|
95
|
+
├── transitions.* duration*, easing*
|
|
96
|
+
├── zIndex.* base, dropdown, sticky, overlay, modal, …
|
|
97
|
+
└── components.* button.*, input.*, card.*, chip.*, …
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`createMuiTheme(tokens)` converts these into a MUI `Theme` and also
|
|
101
|
+
attaches the raw tokens as `theme.tokens` (via TypeScript module
|
|
102
|
+
augmentation). So inside any styled component you can write:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const StyledDiv = styled('div')(({ theme }) => ({
|
|
106
|
+
borderRadius: theme.tokens.borderRadius.md, // ✅ from active theme
|
|
107
|
+
padding: theme.tokens.spacing.lg, // ✅ from active theme
|
|
108
|
+
color: theme.tokens.colors.textPrimary, // ✅ from active theme
|
|
109
|
+
// borderRadius: '8px', // ❌ never do this
|
|
110
|
+
}));
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Adding a new theme
|
|
116
|
+
|
|
117
|
+
1. Create `src/themes/theme3/index.ts` and export a `ThemeTokens` object.
|
|
118
|
+
2. Add `'theme3'` to the `ThemeName` union in `src/themes/registry.ts`.
|
|
119
|
+
3. Register it in the `themeRegistry` map in the same file.
|
|
120
|
+
4. Set `VITE_THEME=theme3` (or equivalent) in your `.env`.
|
|
121
|
+
|
|
122
|
+
TypeScript will enforce that every token is provided — no partial themes.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Adding a new component
|
|
127
|
+
|
|
128
|
+
1. Create `src/components/MyComponent/MyComponent.tsx`.
|
|
129
|
+
2. Use `styled()` from `@mui/material/styles` and reference **only**
|
|
130
|
+
`theme.tokens.*` values — never string literals for visual properties.
|
|
131
|
+
3. Export from `src/components/MyComponent/index.ts`.
|
|
132
|
+
4. Re-export from `src/index.ts`.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Installation
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
yarn install
|
|
140
|
+
yarn build
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Peer dependencies (install in your consuming app):
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
yarn add @mui/material @emotion/react @emotion/styled react react-dom
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## command used to create the foundational components
|
|
150
|
+
|
|
151
|
+
nder the src/components/foundation folder i want to add
|
|
152
|
+
wrapper objects for each of the following. these objects will
|
|
153
|
+
live in their own component file. not 1 big file
|
|
154
|
+
each component will extend the base typography component in the
|
|
155
|
+
mui-design library
|
|
156
|
+
H1
|
|
157
|
+
|
|
158
|
+
<div class="css-1pjc7v5"><h1 class="MuiTypography-root
|
|
159
|
+
MuiTypography-h1 css-p6re0n">How can you choose a
|
|
160
|
+
typeface?</h1><pre class="MuiBox-root css-6cymt6">{
|
|
161
|
+
"fontWeight": 800,
|
|
162
|
+
"fontSize": "2.5rem (40px)",
|
|
163
|
+
"lineHeight": 1.25,
|
|
164
|
+
"@media (min-width:600px)": {
|
|
165
|
+
"fontSize": "3.25rem (52px)"
|
|
166
|
+
},
|
|
167
|
+
"@media (min-width:900px)": {
|
|
168
|
+
"fontSize": "3.625rem (58px)"
|
|
169
|
+
},
|
|
170
|
+
"@media (min-width:1200px)": {
|
|
171
|
+
"fontSize": "4rem (64px)"
|
|
172
|
+
}
|
|
173
|
+
}</pre></div>
|
|
174
|
+
⎿ Interrupted · What should Claude do instead?
|
|
175
|
+
|
|
176
|
+
[Image #2] (↑ to select)
|
|
177
|
+
─────────────────────────────────────────────────────────── ▪▪▪ ─
|
|
178
|
+
❯ under the src/components/foundation folder i want to add
|
|
179
|
+
wrapper objects for each of the following. these objects will
|
|
180
|
+
live in their own component file. not 1 big file
|
|
181
|
+
each component will extend the base typography component in
|
|
182
|
+
the mui-design library
|
|
183
|
+
for each component i will give 2 lines for the name of the
|
|
184
|
+
component and what to export it as, the div element that
|
|
185
|
+
contains the component itself as it is used on a web page and
|
|
186
|
+
the pre object that contains the styles for the component
|
|
187
|
+
rules for each component
|
|
188
|
+
always use the theme values rather than hardcoding values
|
|
189
|
+
i.e fontweight:800, the 800 should come from the theme
|
|
190
|
+
definition
|
|
191
|
+
also create the storybook entry from the component entry i
|
|
192
|
+
have provided above showing the component name, example text,
|
|
193
|
+
and the styles from the pre section to show the styles that
|
|
194
|
+
make up the component all on a card like this
|
|
195
|
+
|
|
196
|
+
all the theme elements can be found in docs/theme.json which
|
|
197
|
+
is a json object showing all the current default theme values
|
|
198
|
+
H1
|
|
199
|
+
[Pasted text #1 +13 lines]
|
|
200
|
+
H2
|
|
201
|
+
[Pasted text #3 +13 lines]
|
|
202
|
+
H3
|
|
203
|
+
[Pasted text #4 +13 lines]
|
|
204
|
+
H4
|
|
205
|
+
[Pasted text #5 +7 lines]
|
|
206
|
+
H5
|
|
207
|
+
[Pasted text #6 +7 lines]
|
|
208
|
+
H6
|
|
209
|
+
[Pasted text #7 +7 lines]
|
|
210
|
+
Subtitle1
|
|
211
|
+
[Pasted text #8 +4 lines]
|
|
212
|
+
Subtitle2
|
|
213
|
+
[Pasted text #9 +4 lines]
|
|
214
|
+
Body1
|
|
215
|
+
[Pasted text #10 +4 lines]
|
|
216
|
+
Body2
|
|
217
|
+
[Pasted text #11 +4 lines]
|
|
218
|
+
Caption
|
|
219
|
+
[Pasted text #12 +4 lines]
|
|
220
|
+
Overline
|
|
221
|
+
[Pasted text #13 +4 lines]
|
|
222
|
+
Button
|
|
223
|
+
[Pasted text #14 +4 lines]
|
|
224
|
+
use the text.primary values from the theme palette object as
|
|
225
|
+
the text colour and use the theme entry from the typeography
|
|
226
|
+
object for each component
|
|
227
|
+
for example H1 fontweight should come from the them value
|
|
228
|
+
typography.h1.fontWeight
|
|
229
|
+
at the end if you can add tests for each component
|
|
230
|
+
build and check for completness
|
|
231
|
+
i can use storybook to see if the components creation worked
|