@underverse-ui/underverse 0.1.12 → 0.1.13

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.
Files changed (2) hide show
  1. package/README.md +65 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -63,6 +63,7 @@ function App() {
63
63
 
64
64
  ### Utilities
65
65
  - `ClientOnly`, `Loading`, `NotificationModal`, `FloatingContacts`, `AccessDenied`
66
+ - Headless controls: `ThemeToggle`, `LanguageSwitcher`
66
67
  - Utility functions: `cn`, `DateUtils`, style constants
67
68
 
68
69
  ## Important Notes
@@ -132,3 +133,67 @@ MIT
132
133
  ## Author
133
134
 
134
135
  Tran Van Bach
136
+
137
+ ---
138
+
139
+ ## Headless Components Usage
140
+
141
+ These variants avoid app-specific contexts and routing so you can wire them to your own state.
142
+
143
+ ### ThemeToggle (headless)
144
+
145
+ ```tsx
146
+ import { ThemeToggle } from '@underverse-ui/underverse';
147
+ import type { ThemeToggleProps, ThemeMode } from '@underverse-ui/underverse';
148
+ import { useState } from 'react';
149
+
150
+ export default function ExampleThemeToggle() {
151
+ const [theme, setTheme] = useState<ThemeMode>('system');
152
+ return (
153
+ <ThemeToggle
154
+ theme={theme}
155
+ onChange={setTheme}
156
+ // optional labels
157
+ labels={{ heading: 'Theme', light: 'Light', dark: 'Dark', system: 'System' }}
158
+ />
159
+ );
160
+ }
161
+ ```
162
+
163
+ If you use `next-themes` or a custom context, pass your current theme and the setter to `onChange`.
164
+
165
+ ### LanguageSwitcher (headless)
166
+
167
+ ```tsx
168
+ import { LanguageSwitcher } from '@underverse-ui/underverse';
169
+ import type { LanguageOption } from '@underverse-ui/underverse';
170
+ import { useRouter, usePathname } from 'next/navigation';
171
+
172
+ const locales: LanguageOption[] = [
173
+ { code: 'vi', name: 'Tiếng Việt', flag: '🇻🇳' },
174
+ { code: 'en', name: 'English', flag: '🇺🇸' },
175
+ { code: 'ko', name: '한국어', flag: '🇰🇷' },
176
+ { code: 'ja', name: '日本語', flag: '🇯🇵' }
177
+ ];
178
+
179
+ export default function ExampleLanguageSwitcher({ currentLocale }: { currentLocale: string }) {
180
+ const router = useRouter();
181
+ const pathname = usePathname();
182
+
183
+ const onSwitch = (code: string) => {
184
+ // Replace first segment as locale, e.g. /vi/... -> /en/...
185
+ const segs = pathname.split('/');
186
+ segs[1] = code;
187
+ router.push(segs.join('/'));
188
+ };
189
+
190
+ return (
191
+ <LanguageSwitcher
192
+ locales={locales}
193
+ currentLocale={currentLocale}
194
+ onSwitch={onSwitch}
195
+ labels={{ heading: 'Language' }}
196
+ />
197
+ );
198
+ }
199
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@underverse-ui/underverse",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "private": false,
5
5
  "description": "Underverse UI – reusable React/Next.js UI components",
6
6
  "type": "module",