@fluxwp/ui 0.0.0-stage → 0.3.3
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 +57 -2
- package/package.json +59 -4
- package/src/Avatar.tsx +12 -0
- package/src/Check.tsx +66 -0
- package/src/DatePicker.tsx +620 -0
- package/src/Empty.tsx +16 -0
- package/src/Icon.tsx +76 -0
- package/src/MenuIcon.tsx +36 -0
- package/src/Modal.tsx +19 -0
- package/src/index.ts +10 -0
- package/src/menu-icons/flx-admin.svg +13 -0
- package/src/menu-icons/flx-ai.svg +15 -0
- package/src/menu-icons/flx-analytics.svg +14 -0
- package/src/menu-icons/flx-app.svg +17 -0
- package/src/menu-icons/flx-backup.svg +13 -0
- package/src/menu-icons/flx-certificates.svg +13 -0
- package/src/menu-icons/flx-chat.svg +13 -0
- package/src/menu-icons/flx-donate.svg +13 -0
- package/src/menu-icons/flx-forms.svg +13 -0
- package/src/menu-icons/flx-lang.svg +13 -0
- package/src/menu-icons/flx-mail.svg +13 -0
- package/src/menu-icons/flx-qr-menu.svg +21 -0
- package/src/menu-icons/flx-roles.svg +17 -0
- package/src/menu-icons/flx-seo.svg +13 -0
- package/src/menu-icons/flx-setup.svg +2 -0
- package/src/menu-icons/flx-social.svg +19 -0
- package/src/menu-icons/flx-speed.svg +12 -0
- package/src/menu-icons/flx-studio.svg +16 -0
- package/src/menu-icons/flx-tasks.svg +13 -0
- package/src/menu-icons/flx-tv-board.svg +14 -0
- package/src/menu-icons/flx-tv-remote.svg +18 -0
- package/src/overlay.ts +15 -0
- package/src/sanitize.ts +91 -0
- package/src/styles.css +396 -0
- package/types/Avatar.d.ts +6 -0
- package/types/Check.d.ts +30 -0
- package/types/DatePicker.d.ts +65 -0
- package/types/Empty.d.ts +7 -0
- package/types/Icon.d.ts +5 -0
- package/types/MenuIcon.d.ts +6 -0
- package/types/Modal.d.ts +7 -0
- package/types/index.d.ts +9 -0
- package/types/overlay.d.ts +6 -0
- package/types/sanitize.d.ts +6 -0
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fluxwp/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@fluxwp/ui)
|
|
4
|
+
[](#license)
|
|
5
|
+
|
|
6
|
+
**The React UI kit of FluxWP screens.** Accessible, theme-aware components that look the same in
|
|
7
|
+
wp-admin, the FluxWP desktop app and the web, and match the PHP side (`flx_check()`, the date picker of
|
|
8
|
+
`flx-brand`), so classic and React screens of a plugin look alike.
|
|
9
|
+
|
|
10
|
+
| Component | |
|
|
11
|
+
|---|---|
|
|
12
|
+
| `Check` | Checkbox, radio and switch in one (`switch`, `radio`, `indeterminate`, `note`, `error`) |
|
|
13
|
+
| `DatePicker`, `DateCalendar` | Date picker with quick ranges and an Apply button, a sheet on phones; `formatDate`, `parseDate` |
|
|
14
|
+
| `Modal`, `useOverlay` | Dialogs and overlays |
|
|
15
|
+
| `Icon`, `MenuIcon` | Icons (Lucide) and the FluxWP plugin menu icons |
|
|
16
|
+
| `Avatar`, `Empty`, `Loading` | Small building blocks |
|
|
17
|
+
| `sanitizeHtml`, `openSanitizedLink` | Safe HTML from the server |
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm i @fluxwp/ui react
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import '@fluxwp/ui/styles.css'; // not needed inside wp-admin with Flux GraphQL: the styles are on the page
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { Check, DatePicker, Modal } from '@fluxwp/ui';
|
|
33
|
+
|
|
34
|
+
<Check checked={on} onChange={setOn} switch>Send e-mail</Check>
|
|
35
|
+
<DatePicker value={date} onChange={setDate} />
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Colours, spacing and dark mode come from [`@fluxwp/tokens`](https://www.npmjs.com/package/@fluxwp/tokens)
|
|
39
|
+
CSS variables (`--flux-*`).
|
|
40
|
+
|
|
41
|
+
## The FluxWP packages
|
|
42
|
+
|
|
43
|
+
| Package | What it is |
|
|
44
|
+
|---|---|
|
|
45
|
+
| [`@fluxwp/plugin-kit`](https://www.npmjs.com/package/@fluxwp/plugin-kit) | Build wp-admin React screens for your own WordPress plugin (Vite preset + `flx-kit` codegen) |
|
|
46
|
+
| [`@fluxwp/graphql`](https://www.npmjs.com/package/@fluxwp/graphql) | Typed GraphQL client and React hooks for Flux GraphQL (WPGraphQL) |
|
|
47
|
+
| [`@fluxwp/host`](https://www.npmjs.com/package/@fluxwp/host) | Host context of a screen: site client, user, locale |
|
|
48
|
+
| [`@fluxwp/ui`](https://www.npmjs.com/package/@fluxwp/ui) | React UI kit of FluxWP screens: Check, DatePicker, Modal, Icon … |
|
|
49
|
+
| [`@fluxwp/core`](https://www.npmjs.com/package/@fluxwp/core) | WordPress REST client, sign-in (OAuth PKCE, app passwords), accounts, i18n |
|
|
50
|
+
| [`@fluxwp/tokens`](https://www.npmjs.com/package/@fluxwp/tokens) | Design tokens: colours, spacing, radius, type, light / dark |
|
|
51
|
+
|
|
52
|
+
[FluxWP](https://fluxwp.com) is an open-source, all-in-one WordPress suite (donations, forms, e-commerce,
|
|
53
|
+
CRM, e-mail, AI, SEO) with a desktop and mobile app. Source:
|
|
54
|
+
[github.com/FluxWP/FluxWP](https://github.com/FluxWP/FluxWP). Questions and ideas: info@fluxwp.com.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
GPL-2.0-or-later
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluxwp/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"description": "React UI kit of FluxWP wp-admin screens: checkbox/switch, date picker, modal, icons; light and dark.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"fluxwp",
|
|
7
|
+
"wordpress",
|
|
8
|
+
"typescript",
|
|
9
|
+
"react",
|
|
10
|
+
"ui",
|
|
11
|
+
"components",
|
|
12
|
+
"wp-admin",
|
|
13
|
+
"date-picker",
|
|
14
|
+
"checkbox",
|
|
15
|
+
"switch",
|
|
16
|
+
"dark-mode"
|
|
17
|
+
],
|
|
18
|
+
"author": "FluxWP <info@fluxwp.com> (https://fluxwp.com)",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"license": "GPL-2.0-or-later",
|
|
21
|
+
"homepage": "https://github.com/FluxWP/FluxWP/tree/main/packages/ui#readme",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/FluxWP/FluxWP.git",
|
|
25
|
+
"directory": "packages/ui"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/FluxWP/FluxWP/issues",
|
|
29
|
+
"email": "info@fluxwp.com"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./types/index.d.ts",
|
|
34
|
+
"default": "./src/index.ts"
|
|
35
|
+
},
|
|
36
|
+
"./styles.css": "./src/styles.css"
|
|
37
|
+
},
|
|
38
|
+
"types": "./types/index.d.ts",
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"types",
|
|
42
|
+
"dist",
|
|
43
|
+
"schema",
|
|
44
|
+
"runtime-exports.json",
|
|
45
|
+
"README.md"
|
|
46
|
+
],
|
|
47
|
+
"sideEffects": [
|
|
48
|
+
"*.css"
|
|
49
|
+
],
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@fluxwp/core": "^0.4.6",
|
|
52
|
+
"@fluxwp/tokens": "^0.4.1",
|
|
53
|
+
"lucide-react": "^1.66.0",
|
|
54
|
+
"react": "19.3.0",
|
|
55
|
+
"zustand": "^5.0.16"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public",
|
|
59
|
+
"provenance": true
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/Avatar.tsx
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function Avatar({ src, name, size = 28, square }: { src?: string; name: string; size?: number; square?: boolean }) {
|
|
2
|
+
const words = name.split(/\s+/).filter((w) => /^\p{L}/u.test(w));
|
|
3
|
+
const initials = (words.length ? words.map((w) => w[0]).slice(0, 2).join('') : '#').toLocaleUpperCase('tr');
|
|
4
|
+
const style = { width: size, height: size, borderRadius: square ? 8 : size };
|
|
5
|
+
return src ? (
|
|
6
|
+
<img className="avatar" src={src} alt="" style={style} />
|
|
7
|
+
) : (
|
|
8
|
+
<span className="avatar avatar-fallback" style={{ ...style, fontSize: size * 0.4 }}>
|
|
9
|
+
{initials}
|
|
10
|
+
</span>
|
|
11
|
+
);
|
|
12
|
+
}
|
package/src/Check.tsx
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useEffect, useRef, type ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
onChange: (checked: boolean) => void;
|
|
6
|
+
/** Etiket (düz metin ya da düğüm). */
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
/** Etiketin altındaki küçük açıklama. */
|
|
9
|
+
note?: ReactNode;
|
|
10
|
+
/** Anahtar görünümü (role="switch"). */
|
|
11
|
+
switch?: boolean;
|
|
12
|
+
/** Radyo (tek seçim); `name` ile gruplanır. */
|
|
13
|
+
radio?: boolean;
|
|
14
|
+
/** Kısmen seçili (yalnız onay kutusu). */
|
|
15
|
+
indeterminate?: boolean;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** Hata iletisi; verilirse kutu hata durumunda gösterilir. */
|
|
18
|
+
error?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
value?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
/** Etiket yoksa ekran okuyucu için ad. */
|
|
23
|
+
'aria-label'?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Ortak onay kutusu / radyo / anahtar. Gerçek `<input>` korunur (klavye, form, ekran okuyucu);
|
|
29
|
+
* görünüm @fluxwp/ui stilleri ve flx-brand `flx_check` ile aynıdır.
|
|
30
|
+
*/
|
|
31
|
+
export function Check({ checked, onChange, children, note, switch: asSwitch, radio, indeterminate, disabled, error, name, value, id, className, ...rest }: Props) {
|
|
32
|
+
const ref = useRef<HTMLInputElement>(null);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (ref.current) ref.current.indeterminate = !!indeterminate && !checked && !radio;
|
|
35
|
+
}, [indeterminate, checked, radio]);
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
<label className={['chk', disabled ? 'is-disabled' : '', className ?? ''].filter(Boolean).join(' ')}>
|
|
39
|
+
<input
|
|
40
|
+
ref={ref}
|
|
41
|
+
id={id}
|
|
42
|
+
name={name}
|
|
43
|
+
value={value}
|
|
44
|
+
type={radio ? 'radio' : 'checkbox'}
|
|
45
|
+
role={asSwitch && !radio ? 'switch' : undefined}
|
|
46
|
+
checked={checked}
|
|
47
|
+
disabled={disabled}
|
|
48
|
+
aria-invalid={error ? true : undefined}
|
|
49
|
+
aria-label={rest['aria-label']}
|
|
50
|
+
onChange={(e) => onChange(e.target.checked)}
|
|
51
|
+
/>
|
|
52
|
+
{children != null || note != null ? (
|
|
53
|
+
<span className="chk__text">
|
|
54
|
+
{children}
|
|
55
|
+
{note != null ? <small>{note}</small> : null}
|
|
56
|
+
</span>
|
|
57
|
+
) : null}
|
|
58
|
+
</label>
|
|
59
|
+
{error ? (
|
|
60
|
+
<p className="chk__msg" role="alert">
|
|
61
|
+
{error}
|
|
62
|
+
</p>
|
|
63
|
+
) : null}
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
}
|