@onvoi/ui 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +28 -2
- package/package.json +16 -4
- package/src/index.js +73 -0
- package/src/styles.css +48 -0
- package/src/tokens.js +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Onvoi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @onvoi/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small React component kit for apps built on Onvoi — calm, accessible and
|
|
4
|
+
mobile-first, with the same fonts and colours as Onvoi. Optional: apps run
|
|
5
|
+
without it. No Onvoi branding; using it doesn't imply endorsement.
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
import { App, Page, Card, Button, Field, Input, Table, Badge } from '@onvoi/ui';
|
|
9
|
+
import '@onvoi/ui/styles.css';
|
|
10
|
+
|
|
11
|
+
export default function Inventory({ items }) {
|
|
12
|
+
return (
|
|
13
|
+
<App>
|
|
14
|
+
<Page title="Inventory" actions={<Button>Add item</Button>}>
|
|
15
|
+
<Card title="Stock">
|
|
16
|
+
<Table columns={[{ key: 'sku', label: 'SKU' }, { key: 'qty', label: 'Qty', render: (r) => r.qty < 5 ? <Badge color="amber">{r.qty}</Badge> : r.qty }]} rows={items} />
|
|
17
|
+
</Card>
|
|
18
|
+
</Page>
|
|
19
|
+
</App>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Components: App, Page, Card, Button (primary / secondary / danger), Field
|
|
25
|
+
(label + hint/error, wired for screen readers), Input, Textarea, Select,
|
|
26
|
+
Badge (accent colours), Alert, Table (scrolls on phones), Stack, Row.
|
|
27
|
+
Tokens: `import { neutrals, accents, font } from '@onvoi/ui/tokens'`.
|
|
28
|
+
|
|
29
|
+
Peer dependency: React 18+. MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onvoi/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A small React component kit for apps built on Onvoi: calm, accessible, mobile-first. No branding.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "src/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.js",
|
|
10
|
+
"./styles.css": "./src/styles.css",
|
|
11
|
+
"./tokens": "./src/tokens.js"
|
|
12
|
+
},
|
|
13
|
+
"files": ["src", "README.md", "LICENSE"],
|
|
14
|
+
"sideEffects": ["*.css"],
|
|
15
|
+
"peerDependencies": { "react": ">=18" },
|
|
16
|
+
"scripts": { "test": "node --test test/*.test.mjs" },
|
|
17
|
+
"keywords": ["onvoi", "react", "components", "design-system"]
|
|
18
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @onvoi/ui — small, dependency-free React components (no JSX build needed).
|
|
2
|
+
// import { Page, Card, Button, Field, Input, Table, Badge, Alert } from '@onvoi/ui';
|
|
3
|
+
// import '@onvoi/ui/styles.css';
|
|
4
|
+
import { createElement as h, useId } from 'react';
|
|
5
|
+
import { accents } from './tokens.js';
|
|
6
|
+
|
|
7
|
+
export * from './tokens.js';
|
|
8
|
+
|
|
9
|
+
const cx = (...c) => c.filter(Boolean).join(' ');
|
|
10
|
+
|
|
11
|
+
/** The app frame: wraps everything in the kit's font and colours. */
|
|
12
|
+
export function App({ children, className }) { return h('div', { className: cx('ou', className) }, children); }
|
|
13
|
+
|
|
14
|
+
export function Page({ title, subtitle, actions, children }) {
|
|
15
|
+
return h('main', { className: 'ou-page' },
|
|
16
|
+
(title || actions) && h('div', { className: 'ou-page-head' },
|
|
17
|
+
h('div', null, title && h('h1', { className: 'ou-title' }, title), subtitle && h('p', { className: 'ou-subtitle' }, subtitle)),
|
|
18
|
+
actions && h('div', { className: 'ou-row' }, actions)),
|
|
19
|
+
children);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Card({ title, children, className, ...rest }) {
|
|
23
|
+
return h('section', { className: cx('ou-card', className), ...rest }, title && h('h2', { className: 'ou-card-title' }, title), children);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function Button({ variant = 'primary', type = 'button', className, children, ...rest }) {
|
|
27
|
+
return h('button', { type, className: cx('ou-btn', `ou-btn-${variant}`, className), ...rest }, children);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Label + control + hint/error, with the accessibility wiring done for you. */
|
|
31
|
+
export function Field({ label, hint, error, children, id: idProp }) {
|
|
32
|
+
const auto = useId();
|
|
33
|
+
const id = idProp || auto;
|
|
34
|
+
const describedBy = error ? `${id}-err` : hint ? `${id}-hint` : undefined;
|
|
35
|
+
const control = typeof children === 'function' ? children({ id, 'aria-describedby': describedBy, 'aria-invalid': error ? 'true' : undefined }) : children;
|
|
36
|
+
return h('div', { className: 'ou-field' },
|
|
37
|
+
label && h('label', { className: 'ou-label', htmlFor: id }, label),
|
|
38
|
+
control,
|
|
39
|
+
error ? h('div', { id: `${id}-err`, className: 'ou-error-text', role: 'alert' }, error)
|
|
40
|
+
: hint && h('div', { id: `${id}-hint`, className: 'ou-hint' }, hint));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function Input({ className, ...rest }) { return h('input', { className: cx('ou-input', className), ...rest }); }
|
|
44
|
+
export function Textarea({ className, ...rest }) { return h('textarea', { className: cx('ou-textarea', className), ...rest }); }
|
|
45
|
+
export function Select({ options = [], className, ...rest }) {
|
|
46
|
+
return h('select', { className: cx('ou-select', className), ...rest },
|
|
47
|
+
options.map((o) => (typeof o === 'string' ? h('option', { key: o, value: o }, o) : h('option', { key: o.value, value: o.value }, o.label))));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A coloured pill. `color` is one of the accent names (red, blue, green, …). */
|
|
51
|
+
export function Badge({ color = 'blue', children }) {
|
|
52
|
+
const a = accents.find((x) => x.name === color) || accents[1];
|
|
53
|
+
return h('span', { className: 'ou-badge', style: { color: a.text, background: a.fill } }, children);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function Alert({ tone = 'info', children }) {
|
|
57
|
+
return h('div', { className: cx('ou-alert', `ou-alert-${tone}`), role: tone === 'danger' ? 'alert' : 'status' }, children);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* columns: [{ key, label, render?(row) }], rows: [...]. Scrolls sideways on a
|
|
62
|
+
* phone instead of breaking the page.
|
|
63
|
+
*/
|
|
64
|
+
export function Table({ columns = [], rows = [], rowKey = (r, i) => r._id || r.id || i, empty = 'Nothing here yet.' }) {
|
|
65
|
+
if (!rows.length) return h('div', { className: 'ou-empty' }, empty);
|
|
66
|
+
return h('div', { className: 'ou-table-wrap' },
|
|
67
|
+
h('table', { className: 'ou-table' },
|
|
68
|
+
h('thead', null, h('tr', null, columns.map((c) => h('th', { key: c.key, scope: 'col' }, c.label)))),
|
|
69
|
+
h('tbody', null, rows.map((r, i) => h('tr', { key: rowKey(r, i) }, columns.map((c) => h('td', { key: c.key }, c.render ? c.render(r) : String(r[c.key] ?? ''))))))));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function Stack({ children }) { return h('div', { className: 'ou-stack' }, children); }
|
|
73
|
+
export function Row({ children }) { return h('div', { className: 'ou-row' }, children); }
|
package/src/styles.css
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* @onvoi/ui — import once: import '@onvoi/ui/styles.css'.
|
|
2
|
+
Fonts: add <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Host+Grotesk:wght@400;500;600;700&display=swap"> */
|
|
3
|
+
:root {
|
|
4
|
+
--ou-font: 'Host Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
|
|
5
|
+
--ou-ink: #15151a; --ou-muted: #6b6b73; --ou-border: #e3e3e6; --ou-bg: #ffffff; --ou-subtle: #f6f6f7;
|
|
6
|
+
--ou-danger: #D55753; --ou-danger-fill: #FEF5F4;
|
|
7
|
+
--ou-red: #D55753; --ou-red-fill: #FEF5F4; --ou-blue: #0094D5; --ou-blue-fill: #F1F9FD;
|
|
8
|
+
--ou-green: #325916; --ou-green-fill: #F2F8EF; --ou-amber: #CC6600; --ou-amber-fill: #FDF6F1;
|
|
9
|
+
--ou-violet: #5D7EE6; --ou-violet-fill: #F5F8FF; --ou-magenta: #C5599F; --ou-magenta-fill: #FDF5F9;
|
|
10
|
+
--ou-emerald: #00A15B; --ou-emerald-fill: #F3FAF5; --ou-orchid: #966CD7; --ou-orchid-fill: #F8F6FE;
|
|
11
|
+
--ou-radius: 10px; --ou-radius-card: 12px;
|
|
12
|
+
}
|
|
13
|
+
.ou { font-family: var(--ou-font); color: var(--ou-ink); font-size: 15px; line-height: 1.5; }
|
|
14
|
+
.ou *, .ou *::before, .ou *::after { box-sizing: border-box; }
|
|
15
|
+
.ou-page { max-width: 1040px; margin: 0 auto; padding: 24px 16px 48px; }
|
|
16
|
+
.ou-page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
|
|
17
|
+
.ou-title { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
|
|
18
|
+
.ou-subtitle { color: var(--ou-muted); margin: 4px 0 0; }
|
|
19
|
+
.ou-card { background: var(--ou-bg); border: 1px solid var(--ou-border); border-radius: var(--ou-radius-card); padding: 16px; }
|
|
20
|
+
.ou-card + .ou-card { margin-top: 12px; }
|
|
21
|
+
.ou-card-title { font-size: 16px; font-weight: 600; margin: 0 0 8px; }
|
|
22
|
+
.ou-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: var(--ou-radius); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; border: 1px solid transparent; }
|
|
23
|
+
.ou-btn:focus-visible, .ou-input:focus-visible, .ou-select:focus-visible { outline: 2px solid var(--ou-blue); outline-offset: 2px; }
|
|
24
|
+
.ou-btn[disabled] { opacity: 0.5; cursor: not-allowed; }
|
|
25
|
+
.ou-btn-primary { background: var(--ou-ink); color: #fff; }
|
|
26
|
+
.ou-btn-secondary { background: var(--ou-bg); color: var(--ou-ink); border-color: var(--ou-border); }
|
|
27
|
+
.ou-btn-danger { background: var(--ou-danger-fill); color: var(--ou-danger); }
|
|
28
|
+
.ou-field { display: grid; gap: 6px; margin-bottom: 12px; }
|
|
29
|
+
.ou-label { font-size: 13px; font-weight: 600; }
|
|
30
|
+
.ou-hint { font-size: 13px; color: var(--ou-muted); }
|
|
31
|
+
.ou-error-text { font-size: 13px; color: var(--ou-danger); }
|
|
32
|
+
.ou-input, .ou-select, .ou-textarea { width: 100%; min-height: 40px; border: 1px solid var(--ou-border); border-radius: var(--ou-radius); padding: 8px 12px; font: inherit; font-size: 15px; background: var(--ou-bg); color: var(--ou-ink); }
|
|
33
|
+
.ou-textarea { min-height: 96px; resize: vertical; }
|
|
34
|
+
.ou-input[aria-invalid='true'] { border-color: var(--ou-danger); }
|
|
35
|
+
.ou-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
|
|
36
|
+
.ou-table-wrap { width: 100%; overflow-x: auto; }
|
|
37
|
+
.ou-table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
38
|
+
.ou-table th { text-align: left; font-weight: 600; color: var(--ou-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--ou-border); }
|
|
39
|
+
.ou-table td { padding: 10px; border-bottom: 1px solid var(--ou-border); }
|
|
40
|
+
.ou-table tbody tr:hover { background: var(--ou-subtle); }
|
|
41
|
+
.ou-empty { text-align: center; color: var(--ou-muted); padding: 32px 16px; }
|
|
42
|
+
.ou-alert { border-radius: var(--ou-radius); padding: 10px 12px; font-size: 14px; }
|
|
43
|
+
.ou-alert-info { background: var(--ou-blue-fill); color: var(--ou-blue); }
|
|
44
|
+
.ou-alert-danger { background: var(--ou-danger-fill); color: var(--ou-danger); }
|
|
45
|
+
.ou-alert-success { background: var(--ou-emerald-fill); color: var(--ou-emerald); }
|
|
46
|
+
.ou-stack { display: flex; flex-direction: column; gap: 12px; }
|
|
47
|
+
.ou-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
|
48
|
+
@media (max-width: 640px) { .ou-title { font-size: 20px; } .ou-page { padding: 16px 16px 40px; } }
|
package/src/tokens.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Design tokens shared with the Onvoi web app (Host Grotesk, ink/muted/border
|
|
2
|
+
// neutrals, the 8-colour accent palette as text/fill pairs). Plain values so
|
|
3
|
+
// apps can use them in JS too.
|
|
4
|
+
export const font = "'Host Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif";
|
|
5
|
+
export const neutrals = { ink: '#15151a', muted: '#6b6b73', border: '#e3e3e6', bg: '#ffffff', subtle: '#f6f6f7' };
|
|
6
|
+
export const danger = { text: '#D55753', fill: '#FEF5F4' };
|
|
7
|
+
export const accents = [
|
|
8
|
+
{ name: 'red', text: '#D55753', fill: '#FEF5F4' },
|
|
9
|
+
{ name: 'blue', text: '#0094D5', fill: '#F1F9FD' },
|
|
10
|
+
{ name: 'green', text: '#325916', fill: '#F2F8EF' },
|
|
11
|
+
{ name: 'amber', text: '#CC6600', fill: '#FDF6F1' },
|
|
12
|
+
{ name: 'violet', text: '#5D7EE6', fill: '#F5F8FF' },
|
|
13
|
+
{ name: 'magenta', text: '#C5599F', fill: '#FDF5F9' },
|
|
14
|
+
{ name: 'emerald', text: '#00A15B', fill: '#F3FAF5' },
|
|
15
|
+
{ name: 'orchid', text: '#966CD7', fill: '#F8F6FE' },
|
|
16
|
+
];
|
|
17
|
+
export const radius = { control: 10, card: 12 };
|
|
18
|
+
export const space = (n) => n * 8;
|