oink-ui 1.0.0 → 1.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 +2 -4
- package/dist/core/locale.d.ts +12 -3
- package/dist/core/theme.d.ts +6 -3
- package/dist/oink-ui.cjs +1 -1
- package/dist/oink-ui.js +942 -928
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,12 +65,12 @@ export function App() {
|
|
|
65
65
|
| `defaultTheme` | `'light' \| 'dark' \| 'system'` | `'system'` |
|
|
66
66
|
| `defaultAccent` | `'pink' \| 'orange' \| 'amber' \| 'blue' \| 'violet'` or any `#rrggbb` | `'pink'` |
|
|
67
67
|
| `defaultMotion` | `'auto' \| 'full' \| 'reduced'` | `'auto'` |
|
|
68
|
-
| `locale` | `'zh-CN' \| 'en-US'`
|
|
68
|
+
| `locale` | `'auto' \| 'zh-CN' \| 'en-US'` — `'auto'` follows the browser language: Chinese → `zh-CN`, anything else → `en-US` | `'auto'` |
|
|
69
69
|
| `storageKey` | remember the user's choices in `localStorage` under this key | — |
|
|
70
70
|
|
|
71
71
|
With a custom accent color, the text color on top of it (ink or white) and the darker / lighter variants used for text are derived automatically. `useOink()` reads and changes the theme at runtime.
|
|
72
72
|
|
|
73
|
-
Components render the same markup on the server and the client, so they work with server rendering and static prerendering.
|
|
73
|
+
Components render the same markup on the server and the client, so they work with server rendering and static prerendering. The server can't know the visitor's language, so with `locale="auto"` the server render and the hydration pass use `en-US` and switch to the browser's language right after; if you render on the server, pass `locale` explicitly (for example from the URL or the `Accept-Language` header).
|
|
74
74
|
|
|
75
75
|
## Development
|
|
76
76
|
|
|
@@ -81,8 +81,6 @@ npm run typecheck
|
|
|
81
81
|
npm run build # dist/: ESM + CJS, type declarations, styles.css and per-component style entries
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
Component conventions (in Chinese) are in [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
85
|
-
|
|
86
84
|
Every push to `main` that changes code is released automatically as a new patch version (`1.0.x`) by [`release.yml`](./.github/workflows/release.yml); put `[skip ci]` in the commit message to skip a release.
|
|
87
85
|
|
|
88
86
|
## License
|
package/dist/core/locale.d.ts
CHANGED
|
@@ -3,16 +3,25 @@ import type { Messages } from './messages';
|
|
|
3
3
|
export type { Messages } from './messages';
|
|
4
4
|
/** 组件内置文案和日期格式用的语言 */
|
|
5
5
|
export type OinkLocale = 'zh-CN' | 'en-US';
|
|
6
|
+
/** 语言设置:具体的语言,或 'auto'(跟随浏览器语言,见 detectLocale) */
|
|
7
|
+
export type OinkLocaleSetting = OinkLocale | 'auto';
|
|
6
8
|
/** 各语言的内置文案 */
|
|
7
9
|
export declare const OINK_MESSAGES: Record<OinkLocale, Messages>;
|
|
10
|
+
/** 服务端渲染、以及注水的那一帧用的语言:服务端不知道访客的语言,注水后再换成浏览器的 */
|
|
11
|
+
export declare const SERVER_LOCALE: OinkLocale;
|
|
12
|
+
/** 浏览器语言 → 组件语言:首选语言是任何一种中文(zh、zh-CN、zh-TW、zh-Hant…)用 zh-CN,其它都用 en-US */
|
|
13
|
+
export declare function detectLocale(languages: readonly string[]): OinkLocale;
|
|
8
14
|
export interface LocaleProviderProps {
|
|
9
|
-
/**
|
|
10
|
-
locale?:
|
|
15
|
+
/** 'auto' 跟随浏览器语言;不传(undefined)时沿用外层的设置,最外层是 'auto' */
|
|
16
|
+
locale?: OinkLocaleSetting;
|
|
11
17
|
children?: ReactNode;
|
|
12
18
|
}
|
|
13
19
|
/** 在这一块里切换组件内置文案的语言。可以嵌套,内层优先。OinkProvider 的 locale 就是包了一层它 */
|
|
14
20
|
export declare function LocaleProvider({ locale, children }: LocaleProviderProps): import("react").JSX.Element;
|
|
15
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* 当前语言和对应的内置文案。设置是 'auto'(默认,包括没有 Provider)时跟随浏览器语言:
|
|
23
|
+
* 服务端渲染和注水那一帧是 SERVER_LOCALE,注水后换成浏览器的;只在浏览器里渲染的应用第一帧就是对的
|
|
24
|
+
*/
|
|
16
25
|
export declare function useLocale(): {
|
|
17
26
|
locale: OinkLocale;
|
|
18
27
|
messages: Messages;
|
package/dist/core/theme.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { OinkLocaleSetting } from './locale';
|
|
3
3
|
import type { TailGlyphSource } from './tail';
|
|
4
4
|
export type ThemeMode = 'light' | 'dark' | 'system';
|
|
5
5
|
export type ResolvedTheme = 'light' | 'dark';
|
|
@@ -39,8 +39,11 @@ export interface OinkProviderProps {
|
|
|
39
39
|
storageKey?: string;
|
|
40
40
|
/** 替换全局的“尾巴”图案(加载、提示里用到的品牌图形)。见 TailProvider */
|
|
41
41
|
tail?: TailGlyphSource;
|
|
42
|
-
/**
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* 组件内置文案(默认的读屏文字、按钮文字、占位符……)和日期格式的语言。默认 'auto':跟随浏览器语言,中文用 zh-CN、其它用 en-US。
|
|
44
|
+
* 服务端渲染时第一帧是 en-US、注水后才换成浏览器的语言;服务端渲染的应用最好显式传入。见 LocaleProvider
|
|
45
|
+
*/
|
|
46
|
+
locale?: OinkLocaleSetting;
|
|
44
47
|
}
|
|
45
48
|
/**
|
|
46
49
|
* 主题、强调色、动效偏好。把结果写到 <html> 的 data-theme / data-accent / data-motion 上,
|