@nurvus/ui 0.1.0-alpha.14 → 0.1.0-alpha.15
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 +3 -0
- package/dist/index.js +1 -1
- package/dist/nurvus.css +1 -0
- package/dist/respawn.js +1 -1
- package/dist/types/components/Icon/Icon.d.ts +20 -0
- package/dist/types/icons.d.ts +55 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/respawn/Icon.d.ts +22 -0
- package/dist/types/respawn/index.d.ts +4 -0
- package/dist/types/respawn/spawn.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/ButtonGroup/ButtonGroup.md +8 -12
- package/src/components/Icon/Icon.md +22 -0
- package/src/components/Icon/Icon.scss +10 -0
- package/src/components/Icon/Icon.tsx +45 -0
- package/src/components/Layout/Layout.md +10 -18
- package/src/components/Menu/Menu.md +3 -1
- package/src/components/Text/Text.md +3 -5
- package/src/components/Tree/Tree.md +5 -5
- package/src/css.ts +1 -0
- package/src/icons.ts +88 -0
- package/src/index.ts +4 -0
- package/src/respawn/Icon.ts +47 -0
- package/src/respawn/index.ts +4 -0
- package/src/respawn/spawn.ts +5 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IconName } from '../../icons';
|
|
3
|
+
export interface IconProps extends Omit<React.SVGAttributes<SVGSVGElement>, 'name'> {
|
|
4
|
+
/** Which icon (Foundations > Icons lists them all). */
|
|
5
|
+
name: IconName;
|
|
6
|
+
/** Width and height. Defaults to 1em: the icon is as big as the text around it. A number is pixels. */
|
|
7
|
+
size?: number | string;
|
|
8
|
+
/** Says what the icon means, for an icon that stands alone (screen readers read it). Leave it out when text beside it already says it. */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** Line thickness in grid units (the grid is 24). */
|
|
11
|
+
strokeWidth?: number;
|
|
12
|
+
/** Custom class name. */
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* An icon from the NURVUS set: drawn on a 24-unit grid with round 2-unit
|
|
17
|
+
* lines, in the text's color (currentColor), and 1em by default so it matches
|
|
18
|
+
* the text it sits in. Decorative unless you give it a label.
|
|
19
|
+
*/
|
|
20
|
+
export default function Icon({ name, size, label, strokeWidth, className, ...restProps }: IconProps): React.ReactElement;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** One SVG element of an icon: its tag and attributes. */
|
|
2
|
+
export type IconNode = [tag: 'path' | 'circle' | 'rect', attrs: Record<string, string | number>];
|
|
3
|
+
declare const DEFS: {
|
|
4
|
+
menu: IconNode[];
|
|
5
|
+
close: IconNode[];
|
|
6
|
+
'chevron-down': IconNode[];
|
|
7
|
+
'chevron-up': IconNode[];
|
|
8
|
+
'chevron-left': IconNode[];
|
|
9
|
+
'chevron-right': IconNode[];
|
|
10
|
+
'arrow-left': IconNode[];
|
|
11
|
+
'arrow-right': IconNode[];
|
|
12
|
+
'arrow-up': IconNode[];
|
|
13
|
+
'arrow-down': IconNode[];
|
|
14
|
+
'external-link': IconNode[];
|
|
15
|
+
add: IconNode[];
|
|
16
|
+
remove: IconNode[];
|
|
17
|
+
edit: IconNode[];
|
|
18
|
+
copy: IconNode[];
|
|
19
|
+
delete: IconNode[];
|
|
20
|
+
download: IconNode[];
|
|
21
|
+
upload: IconNode[];
|
|
22
|
+
search: IconNode[];
|
|
23
|
+
filter: IconNode[];
|
|
24
|
+
sliders: IconNode[];
|
|
25
|
+
refresh: IconNode[];
|
|
26
|
+
undo: IconNode[];
|
|
27
|
+
redo: IconNode[];
|
|
28
|
+
check: IconNode[];
|
|
29
|
+
info: IconNode[];
|
|
30
|
+
warning: IconNode[];
|
|
31
|
+
error: IconNode[];
|
|
32
|
+
help: IconNode[];
|
|
33
|
+
file: IconNode[];
|
|
34
|
+
folder: IconNode[];
|
|
35
|
+
image: IconNode[];
|
|
36
|
+
layers: IconNode[];
|
|
37
|
+
eye: IconNode[];
|
|
38
|
+
'eye-off': IconNode[];
|
|
39
|
+
lock: IconNode[];
|
|
40
|
+
unlock: IconNode[];
|
|
41
|
+
link: IconNode[];
|
|
42
|
+
sun: IconNode[];
|
|
43
|
+
moon: IconNode[];
|
|
44
|
+
code: IconNode[];
|
|
45
|
+
terminal: IconNode[];
|
|
46
|
+
};
|
|
47
|
+
/** Every icon's name. */
|
|
48
|
+
export type IconName = keyof typeof DEFS;
|
|
49
|
+
/** Every icon: its name and the shapes it is drawn with. */
|
|
50
|
+
export declare const ICONS: Record<IconName, IconNode[]>;
|
|
51
|
+
/** The names, in the order above (groups: navigation, actions, status, things, theme, code). */
|
|
52
|
+
export declare const ICON_NAMES: IconName[];
|
|
53
|
+
/** An unknown name draws an empty icon and says so once. */
|
|
54
|
+
export declare function iconNodes(name: string): IconNode[];
|
|
55
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export { default as Progress } from './components/Progress/Progress';
|
|
|
12
12
|
export type { ProgressProps, ProgressSize, ProgressStatus } from './components/Progress/Progress';
|
|
13
13
|
export { default as Layout } from './components/Layout/Layout';
|
|
14
14
|
export type { LayoutProps, Spacing, LegacySpacing } from './components/Layout/Layout';
|
|
15
|
+
export { default as Icon } from './components/Icon/Icon';
|
|
16
|
+
export type { IconProps } from './components/Icon/Icon';
|
|
17
|
+
export { ICONS, ICON_NAMES } from './icons';
|
|
18
|
+
export type { IconName, IconNode } from './icons';
|
|
15
19
|
export { default as Tree } from './components/Tree/Tree';
|
|
16
20
|
export type { TreeProps, TreeItem } from './components/Tree/Tree';
|
|
17
21
|
export { default as Menu } from './components/Menu/Menu';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IconName } from '../icons';
|
|
2
|
+
import { ElementProps } from './spawn';
|
|
3
|
+
export interface IconProps extends ElementProps {
|
|
4
|
+
/** Which icon (Foundations > Icons lists them all). */
|
|
5
|
+
name: IconName;
|
|
6
|
+
/** Width and height. Defaults to 1em: the icon is as big as the text around it. A number is pixels. */
|
|
7
|
+
size?: number | string;
|
|
8
|
+
/** Says what the icon means, for an icon that stands alone (screen readers read it). Leave it out when text beside it already says it. */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** Line thickness in grid units (the grid is 24). */
|
|
11
|
+
strokeWidth?: number;
|
|
12
|
+
}
|
|
13
|
+
/** The <svg> Icon returns, with update() like every other component. */
|
|
14
|
+
export type IconElement = SVGSVGElement & {
|
|
15
|
+
update(changes: Partial<IconProps>): IconElement;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* An icon from the NURVUS set, as an <svg> element: the same markup as the
|
|
19
|
+
* React Icon. 1em by default, in the text's color; decorative unless it has a
|
|
20
|
+
* label. icon.update({ name: 'check' }) swaps it for another.
|
|
21
|
+
*/
|
|
22
|
+
export default function Icon(props: IconProps): IconElement;
|
|
@@ -15,6 +15,10 @@ export { default as Progress } from './Progress';
|
|
|
15
15
|
export type { ProgressProps, ProgressSize, ProgressStatus } from './Progress';
|
|
16
16
|
export { default as Layout } from './Layout';
|
|
17
17
|
export type { LayoutProps, Spacing, LegacySpacing } from './Layout';
|
|
18
|
+
export { default as Icon } from './Icon';
|
|
19
|
+
export type { IconProps, IconElement } from './Icon';
|
|
20
|
+
export { ICONS, ICON_NAMES } from '../icons';
|
|
21
|
+
export type { IconName, IconNode } from '../icons';
|
|
18
22
|
export { default as Tree } from './Tree';
|
|
19
23
|
export type { TreeProps, TreeItem } from './Tree';
|
|
20
24
|
export { default as Menu } from './Menu';
|
|
@@ -33,6 +33,8 @@ export interface SpawnProps extends ElementProps {
|
|
|
33
33
|
children?: Child | ((el: HTMLElement) => void);
|
|
34
34
|
/** Appends the new element to this one. */
|
|
35
35
|
mountEl?: Element;
|
|
36
|
+
/** Makes the element in this namespace, e.g. 'http://www.w3.org/2000/svg' for SVG (Icon uses it). */
|
|
37
|
+
namespace?: string;
|
|
36
38
|
}
|
|
37
39
|
/** Appends `child` (any Child) to `parent`. */
|
|
38
40
|
export declare function append(parent: Node, child: Child): void;
|
package/package.json
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
```jsx
|
|
2
|
-
import { Button, ButtonGroup, Layout } from '@nurvus/ui';
|
|
3
|
-
import AddIcon from '@material-ui/icons/Add';
|
|
4
|
-
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
|
5
|
-
import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
|
|
6
|
-
import LockOpenIcon from '@material-ui/icons/LockOpen';
|
|
2
|
+
import { Button, ButtonGroup, Icon, Layout } from '@nurvus/ui';
|
|
7
3
|
|
|
8
4
|
<Layout>
|
|
9
5
|
<ButtonGroup>
|
|
10
|
-
<Button><
|
|
11
|
-
<Button><
|
|
12
|
-
<Button disabled={ true }><
|
|
13
|
-
<Button><
|
|
6
|
+
<Button aria-label="Add"><Icon name="add" size="1.25em" /></Button>
|
|
7
|
+
<Button aria-label="Copy"><Icon name="copy" size="1.25em" /></Button>
|
|
8
|
+
<Button disabled={ true } aria-label="Show"><Icon name="eye" size="1.25em" /></Button>
|
|
9
|
+
<Button aria-label="Unlock"><Icon name="unlock" size="1.25em" /></Button>
|
|
14
10
|
</ButtonGroup>
|
|
15
11
|
|
|
16
12
|
<ButtonGroup>
|
|
17
|
-
<Button disabled={ true }><
|
|
18
|
-
<Button><
|
|
13
|
+
<Button disabled={ true } aria-label="Show"><Icon name="eye" size="1.25em" /></Button>
|
|
14
|
+
<Button aria-label="Unlock"><Icon name="unlock" size="1.25em" /></Button>
|
|
19
15
|
</ButtonGroup>
|
|
20
16
|
|
|
21
17
|
<ButtonGroup>
|
|
22
|
-
<Button><
|
|
18
|
+
<Button aria-label="Unlock"><Icon name="unlock" size="1.25em" /></Button>
|
|
23
19
|
</ButtonGroup>
|
|
24
20
|
</Layout>
|
|
25
21
|
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Icons are 1em by default, so they are as big as the text they sit in, and they take its color. Every icon is in **Foundations → Icons**.
|
|
2
|
+
```jsx
|
|
3
|
+
import { Icon, Layout, Text, Title } from '@nurvus/ui';
|
|
4
|
+
|
|
5
|
+
<Layout itemSpacing={ 12 }>
|
|
6
|
+
<Title level={ 3 }><Icon name="layers" /> Layers</Title>
|
|
7
|
+
<Text as="p" variant="body"><Icon name="info" /> Body text, and its icon is body size.</Text>
|
|
8
|
+
<Text as="p" variant="caption" tone="muted"><Icon name="check" /> A caption, a smaller icon.</Text>
|
|
9
|
+
</Layout>
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
In a button: put the icon beside the words. An icon alone needs a `label`, which screen readers read; with words beside it, leave the label out (the icon is decorative).
|
|
13
|
+
```jsx
|
|
14
|
+
import { Button, Icon, Layout } from '@nurvus/ui';
|
|
15
|
+
|
|
16
|
+
<Layout display="flex" alignItems="center" itemSpacing={ 8 }>
|
|
17
|
+
<Button type="primary"><Icon name="add" /> New layer</Button>
|
|
18
|
+
<Button type="secondary"><Icon name="download" /> Export</Button>
|
|
19
|
+
<Button type="secondary" aria-label="Delete layer"><Icon name="delete" /></Button>
|
|
20
|
+
<Icon name="warning" label="Unsaved changes" size={ 24 } style={ { color: 'var(--nv-warning)' } } />
|
|
21
|
+
</Layout>
|
|
22
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
@import "../../styles/variables.scss";
|
|
2
|
+
|
|
3
|
+
// Icons sit on the text's baseline like a letter: 1em tall, nudged down an
|
|
4
|
+
// eighth so their middle lines up with the middle of capitals and lowercase.
|
|
5
|
+
.#{$cls-prefix}.icon {
|
|
6
|
+
display: inline-block;
|
|
7
|
+
flex: none;
|
|
8
|
+
vertical-align: -0.125em;
|
|
9
|
+
overflow: visible;
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import CONSTANT from '../../constants';
|
|
4
|
+
import { iconNodes, IconName } from '../../icons';
|
|
5
|
+
import './Icon.scss';
|
|
6
|
+
|
|
7
|
+
export interface IconProps extends Omit<React.SVGAttributes<SVGSVGElement>, 'name'> {
|
|
8
|
+
/** Which icon (Foundations > Icons lists them all). */
|
|
9
|
+
name: IconName;
|
|
10
|
+
/** Width and height. Defaults to 1em: the icon is as big as the text around it. A number is pixels. */
|
|
11
|
+
size?: number | string;
|
|
12
|
+
/** Says what the icon means, for an icon that stands alone (screen readers read it). Leave it out when text beside it already says it. */
|
|
13
|
+
label?: string;
|
|
14
|
+
/** Line thickness in grid units (the grid is 24). */
|
|
15
|
+
strokeWidth?: number;
|
|
16
|
+
/** Custom class name. */
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* An icon from the NURVUS set: drawn on a 24-unit grid with round 2-unit
|
|
22
|
+
* lines, in the text's color (currentColor), and 1em by default so it matches
|
|
23
|
+
* the text it sits in. Decorative unless you give it a label.
|
|
24
|
+
*/
|
|
25
|
+
export default function Icon({ name, size = '1em', label, strokeWidth = 2, className, ...restProps }: IconProps) {
|
|
26
|
+
const a11y = label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true, focusable: 'false' as const };
|
|
27
|
+
return (
|
|
28
|
+
<svg
|
|
29
|
+
className={ classNames(className, 'icon', CONSTANT.CLASS_PREFIX) }
|
|
30
|
+
data-icon={ name }
|
|
31
|
+
viewBox="0 0 24 24"
|
|
32
|
+
width={ size }
|
|
33
|
+
height={ size }
|
|
34
|
+
fill="none"
|
|
35
|
+
stroke="currentColor"
|
|
36
|
+
strokeWidth={ strokeWidth }
|
|
37
|
+
strokeLinecap="round"
|
|
38
|
+
strokeLinejoin="round"
|
|
39
|
+
{ ...a11y }
|
|
40
|
+
{ ...restProps }
|
|
41
|
+
>
|
|
42
|
+
{ iconNodes(name).map(([tag, attrs], i) => React.createElement(tag, { key: i, ...attrs })) }
|
|
43
|
+
</svg>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -1,34 +1,26 @@
|
|
|
1
1
|
Basic Example
|
|
2
2
|
```jsx
|
|
3
|
-
import { Button, Layout, Title } from '@nurvus/ui';
|
|
4
|
-
import AddIcon from '@material-ui/icons/Add';
|
|
5
|
-
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
|
6
|
-
import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
|
|
7
|
-
import LockOpenIcon from '@material-ui/icons/LockOpen';
|
|
3
|
+
import { Button, Icon, Layout, Title } from '@nurvus/ui';
|
|
8
4
|
|
|
9
5
|
<Layout>
|
|
10
6
|
<Title level={ 3 }>Layers</Title>
|
|
11
|
-
<Button>
|
|
12
|
-
<
|
|
7
|
+
<Button aria-label="Add">
|
|
8
|
+
<Icon name="add" size="1.25em" />
|
|
13
9
|
</Button>
|
|
14
10
|
</Layout>
|
|
15
11
|
```
|
|
16
12
|
|
|
17
13
|
Horizontal Example
|
|
18
14
|
```jsx
|
|
19
|
-
import { Button, Layout, Title } from '@nurvus/ui';
|
|
20
|
-
import AddIcon from '@material-ui/icons/Add';
|
|
21
|
-
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
|
22
|
-
import RemoveRedEyeIcon from '@material-ui/icons/RemoveRedEye';
|
|
23
|
-
import LockOpenIcon from '@material-ui/icons/LockOpen';
|
|
15
|
+
import { Button, Icon, Layout, Title } from '@nurvus/ui';
|
|
24
16
|
|
|
25
17
|
<Layout itemSpacing={ 32 }>
|
|
26
18
|
<Layout itemSpacing={ 8 }>
|
|
27
19
|
<Title level={ 4 }>Display Flex</Title>
|
|
28
20
|
<Layout display="flex">
|
|
29
21
|
<Title level={ 3 }>Layers</Title>
|
|
30
|
-
<Button>
|
|
31
|
-
<
|
|
22
|
+
<Button aria-label="Add">
|
|
23
|
+
<Icon name="add" size="1.25em" />
|
|
32
24
|
</Button>
|
|
33
25
|
</Layout>
|
|
34
26
|
</Layout>
|
|
@@ -36,8 +28,8 @@ import LockOpenIcon from '@material-ui/icons/LockOpen';
|
|
|
36
28
|
<Title level={ 4 }>Display Flex and Align Item</Title>
|
|
37
29
|
<Layout display="flex" alignItems="center">
|
|
38
30
|
<Title level={ 3 }>Layers</Title>
|
|
39
|
-
<Button>
|
|
40
|
-
<
|
|
31
|
+
<Button aria-label="Add">
|
|
32
|
+
<Icon name="add" size="1.25em" />
|
|
41
33
|
</Button>
|
|
42
34
|
</Layout>
|
|
43
35
|
</Layout>
|
|
@@ -45,8 +37,8 @@ import LockOpenIcon from '@material-ui/icons/LockOpen';
|
|
|
45
37
|
<Title level={ 4 }>Display Flex and Align Item and Spaced Apart</Title>
|
|
46
38
|
<Layout display="flex" alignItems="center" justifyContent="space-between">
|
|
47
39
|
<Title level={ 3 }>Layers</Title>
|
|
48
|
-
<Button>
|
|
49
|
-
<
|
|
40
|
+
<Button aria-label="Add">
|
|
41
|
+
<Icon name="add" size="1.25em" />
|
|
50
42
|
</Button>
|
|
51
43
|
</Layout>
|
|
52
44
|
</Layout>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
**Menu or Tree?** Menu takes people to pages: its rows are links (a `<nav>`), Tab visits each one, and the current page is marked. [Tree](#/Components/Tree) picks an item in a list on the same page, like layers in an editor: one Tab stop, the arrow keys move, and the picked row is selected. Screen readers announce them differently (links in a navigation area versus a tree you choose from), so they are two components with the same look.
|
|
2
|
+
|
|
1
3
|
Sections open and close with the chevron (or the whole heading, when it isn't a link). The current page is marked with a bar beside it, and its section opens by itself.
|
|
2
4
|
|
|
3
|
-
By keyboard: Tab goes link by link as usual, and inside the menu ↑ ↓ move between rows (going round at the ends), Home and End jump to the first and last, → opens a section and ← closes it.
|
|
5
|
+
By keyboard: Tab goes link by link as usual, and inside the menu ↑ ↓ move between rows (going round at the ends), Home and End jump to the first and last, → opens a section and ← closes it. Enter follows a link; Enter or Space opens and closes a section (its chevron is a button). Links take Enter only, as everywhere on the web: Space scrolls the page.
|
|
4
6
|
```jsx
|
|
5
7
|
import { Menu } from '@nurvus/ui';
|
|
6
8
|
|
|
@@ -31,9 +31,7 @@ import { Text } from '@nurvus/ui';
|
|
|
31
31
|
|
|
32
32
|
Using Text Overflow
|
|
33
33
|
```jsx
|
|
34
|
-
import
|
|
35
|
-
import AddIcon from '@material-ui/icons/Add';
|
|
36
|
-
import { Button, Layout, Text } from '@nurvus/ui';
|
|
34
|
+
import { Button, Icon, Layout, Text } from '@nurvus/ui';
|
|
37
35
|
|
|
38
36
|
const overflowStyle = {
|
|
39
37
|
textOverflow: 'ellipsis',
|
|
@@ -43,8 +41,8 @@ const overflowStyle = {
|
|
|
43
41
|
|
|
44
42
|
<Layout display="flex" alignItems="center" justifyContent="space-between">
|
|
45
43
|
<Text style={ overflowStyle }>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</Text>
|
|
46
|
-
<Button>
|
|
47
|
-
<
|
|
44
|
+
<Button aria-label="Add">
|
|
45
|
+
<Icon name="add" size="1.25em" />
|
|
48
46
|
</Button>
|
|
49
47
|
</Layout>
|
|
50
48
|
```
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
**Tree or Menu?** Tree picks an item in a list on the same page (layers, folders, outline). To take people to other pages, use [Menu](#/Components/Menu): its rows are links in a `<nav>`.
|
|
2
|
+
|
|
1
3
|
A list of rows to pick from, nested like a layers panel. Click a row, or use the keyboard: Tab reaches the active row, ↑ ↓ move, → goes to a child row, ← to its parent, Enter or Space picks.
|
|
2
4
|
```jsx
|
|
3
5
|
import { Tree } from '@nurvus/ui';
|
|
@@ -26,16 +28,14 @@ const Layers = () => {
|
|
|
26
28
|
|
|
27
29
|
Draw your own rows with `itemRenderer`, e.g. a layer's name with its show and lock icons.
|
|
28
30
|
```jsx
|
|
29
|
-
import
|
|
30
|
-
import LockOpenIcon from '@material-ui/icons/LockOpen';
|
|
31
|
-
import { Layout, Text, Tree } from '@nurvus/ui';
|
|
31
|
+
import { Icon, Layout, Text, Tree } from '@nurvus/ui';
|
|
32
32
|
|
|
33
33
|
const itemRenderer = ({ label }) => (
|
|
34
34
|
<Layout display="flex" alignItems="center" justifyContent="space-between">
|
|
35
35
|
<Text>{ label }</Text>
|
|
36
36
|
<Layout display="flex" alignItems="center" itemSpacing={ 4 }>
|
|
37
|
-
<
|
|
38
|
-
<
|
|
37
|
+
<Icon name="eye" />
|
|
38
|
+
<Icon name="unlock" />
|
|
39
39
|
</Layout>
|
|
40
40
|
</Layout>
|
|
41
41
|
);
|
package/src/css.ts
CHANGED
|
@@ -7,6 +7,7 @@ import './components/FullPageModal/FullPageModal.scss';
|
|
|
7
7
|
import './components/HistoryList/HistoryList.scss';
|
|
8
8
|
import './components/Layout/Layout.scss';
|
|
9
9
|
import './components/Link/Link.scss';
|
|
10
|
+
import './components/Icon/Icon.scss';
|
|
10
11
|
import './components/Tree/Tree.scss';
|
|
11
12
|
import './components/Menu/Menu.scss';
|
|
12
13
|
import './components/Select/Select.scss';
|
package/src/icons.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// The NURVUS icons, drawn for this library (no icon font, no third-party set).
|
|
2
|
+
// Shared by the React and the Respawn Icon (no React here).
|
|
3
|
+
//
|
|
4
|
+
// The grid: a 24 x 24 artboard with 2 units of padding (a 20 x 20 live area),
|
|
5
|
+
// 2-unit strokes with round caps and joins, corners of radius 2, circles of
|
|
6
|
+
// radius 9. Every shape is a stroke in currentColor unless it says otherwise,
|
|
7
|
+
// so an icon takes the color of the text around it. Icons are 1em by default:
|
|
8
|
+
// next to 16px text they are 16px, in a 22px title 22px.
|
|
9
|
+
|
|
10
|
+
/** One SVG element of an icon: its tag and attributes. */
|
|
11
|
+
export type IconNode = [tag: 'path' | 'circle' | 'rect', attrs: Record<string, string | number>];
|
|
12
|
+
|
|
13
|
+
const path = (d: string): IconNode => ['path', { d }];
|
|
14
|
+
const circle = (cx: number, cy: number, r: number): IconNode => ['circle', { cx, cy, r }];
|
|
15
|
+
const rect = (x: number, y: number, width: number, height: number, rx = 2): IconNode => ['rect', { x, y, width, height, rx }];
|
|
16
|
+
const ring = circle(12, 12, 9);
|
|
17
|
+
const dot = (x: number, y: number) => path(`M${x} ${y}h.01`);
|
|
18
|
+
|
|
19
|
+
const DEFS = {
|
|
20
|
+
// Navigation
|
|
21
|
+
menu: [path('M4 6h16M4 12h16M4 18h16')],
|
|
22
|
+
close: [path('M6 6l12 12M18 6L6 18')],
|
|
23
|
+
'chevron-down': [path('M6 9l6 6 6-6')],
|
|
24
|
+
'chevron-up': [path('M6 15l6-6 6 6')],
|
|
25
|
+
'chevron-left': [path('M15 6l-6 6 6 6')],
|
|
26
|
+
'chevron-right': [path('M9 6l6 6-6 6')],
|
|
27
|
+
'arrow-left': [path('M19 12H5M11 6l-6 6 6 6')],
|
|
28
|
+
'arrow-right': [path('M5 12h14M13 6l6 6-6 6')],
|
|
29
|
+
'arrow-up': [path('M12 19V5M6 11l6-6 6 6')],
|
|
30
|
+
'arrow-down': [path('M12 5v14M6 13l6 6 6-6')],
|
|
31
|
+
'external-link': [path('M14 4h6v6M20 4l-9 9M18 14v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4')],
|
|
32
|
+
// Actions
|
|
33
|
+
add: [path('M12 5v14M5 12h14')],
|
|
34
|
+
remove: [path('M5 12h14')],
|
|
35
|
+
edit: [path('M4 20h4L19 9a2.83 2.83 0 0 0-4-4L4 16v4z'), path('M13.5 6.5l4 4')],
|
|
36
|
+
copy: [rect(8, 8, 12, 12), path('M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2')],
|
|
37
|
+
delete: [path('M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M10 11v6M14 11v6')],
|
|
38
|
+
download: [path('M12 4v11M7 10l5 5 5-5M4 20h16')],
|
|
39
|
+
upload: [path('M12 15V4M7 9l5-5 5 5M4 20h16')],
|
|
40
|
+
search: [circle(11, 11, 6.5), path('M16 16l4 4')],
|
|
41
|
+
filter: [path('M4 5h16l-6 7.5V19l-4 2v-8.5z')],
|
|
42
|
+
sliders: [path('M4 7h10M18 7h2M4 17h4M12 17h8'), circle(16, 7, 2), circle(10, 17, 2)],
|
|
43
|
+
refresh: [path('M19 12a7 7 0 1 1-7-7'), path('M9.5 2.5L12 5l-2.5 2.5')],
|
|
44
|
+
undo: [path('M9 14L4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11')],
|
|
45
|
+
redo: [path('M15 14l5-5-5-5M20 9H9.5a5.5 5.5 0 0 0 0 11H13')],
|
|
46
|
+
// Status
|
|
47
|
+
check: [path('M5 12.5l4.5 4.5L19 7.5')],
|
|
48
|
+
info: [ring, path('M12 11v5'), dot(12, 8)],
|
|
49
|
+
warning: [path('M10.27 4.3L2.6 18a2 2 0 0 0 1.73 3h15.34a2 2 0 0 0 1.73-3L13.73 4.3a2 2 0 0 0-3.46 0z'), path('M12 9.5v4'), dot(12, 17)],
|
|
50
|
+
error: [ring, path('M15 9l-6 6M9 9l6 6')],
|
|
51
|
+
help: [ring, path('M9.5 9.5a2.5 2.5 0 1 1 3.5 2.3c-.7.3-1 .8-1 1.5v.4'), dot(12, 17)],
|
|
52
|
+
// Things
|
|
53
|
+
file: [path('M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z'), path('M14 3v5h5')],
|
|
54
|
+
folder: [path('M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z')],
|
|
55
|
+
image: [rect(3, 4, 18, 16), circle(9, 10, 1.5), path('M21 15l-5-5L6 20')],
|
|
56
|
+
layers: [path('M12 3l9 5-9 5-9-5z'), path('M3 13l9 5 9-5')],
|
|
57
|
+
eye: [path('M2 12s3.6-6 10-6 10 6 10 6-3.6 6-10 6S2 12 2 12z'), circle(12, 12, 3)],
|
|
58
|
+
'eye-off': [path('M3 3l18 18'), path('M10.6 6.1A9.7 9.7 0 0 1 12 6c6.4 0 10 6 10 6a17 17 0 0 1-2.6 3.4M6.6 6.6C3.9 8.4 2 12 2 12s3.6 6 10 6a9.7 9.7 0 0 0 5.4-1.6'), path('M9.9 9.9a3 3 0 0 0 4.2 4.2')],
|
|
59
|
+
lock: [rect(5, 11, 14, 10), path('M8 11V8a4 4 0 0 1 8 0v3')],
|
|
60
|
+
unlock: [rect(5, 11, 14, 10), path('M8 11V8a4 4 0 0 1 7.75-1.4')],
|
|
61
|
+
link: [path('M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1'), path('M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1')],
|
|
62
|
+
// Theme
|
|
63
|
+
sun: [circle(12, 12, 4), path('M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41')],
|
|
64
|
+
moon: [path('M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z')],
|
|
65
|
+
// Code
|
|
66
|
+
code: [path('M8 7l-5 5 5 5M16 7l5 5-5 5')],
|
|
67
|
+
terminal: [path('M4 17l6-5-6-5M12 19h8')],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** Every icon's name. */
|
|
71
|
+
export type IconName = keyof typeof DEFS;
|
|
72
|
+
|
|
73
|
+
/** Every icon: its name and the shapes it is drawn with. */
|
|
74
|
+
export const ICONS: Record<IconName, IconNode[]> = DEFS;
|
|
75
|
+
|
|
76
|
+
/** The names, in the order above (groups: navigation, actions, status, things, theme, code). */
|
|
77
|
+
export const ICON_NAMES = Object.keys(DEFS) as IconName[];
|
|
78
|
+
|
|
79
|
+
let warned = '';
|
|
80
|
+
/** An unknown name draws an empty icon and says so once. */
|
|
81
|
+
export function iconNodes(name: string): IconNode[] {
|
|
82
|
+
const nodes = (ICONS as Record<string, IconNode[]>)[name];
|
|
83
|
+
if (!nodes && warned !== name && typeof console !== 'undefined') {
|
|
84
|
+
warned = name;
|
|
85
|
+
console.warn(`[@nurvus/ui] Icon: there is no icon named "${name}". The names: ${ICON_NAMES.join(', ')}.`);
|
|
86
|
+
}
|
|
87
|
+
return nodes || [];
|
|
88
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,10 @@ export { default as Progress } from './components/Progress/Progress';
|
|
|
22
22
|
export type { ProgressProps, ProgressSize, ProgressStatus } from './components/Progress/Progress';
|
|
23
23
|
export { default as Layout } from './components/Layout/Layout';
|
|
24
24
|
export type { LayoutProps, Spacing, LegacySpacing } from './components/Layout/Layout';
|
|
25
|
+
export { default as Icon } from './components/Icon/Icon';
|
|
26
|
+
export type { IconProps } from './components/Icon/Icon';
|
|
27
|
+
export { ICONS, ICON_NAMES } from './icons';
|
|
28
|
+
export type { IconName, IconNode } from './icons';
|
|
25
29
|
export { default as Tree } from './components/Tree/Tree';
|
|
26
30
|
export type { TreeProps, TreeItem } from './components/Tree/Tree';
|
|
27
31
|
export { default as Menu } from './components/Menu/Menu';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import CONSTANT from '../constants';
|
|
3
|
+
import { iconNodes, IconName } from '../icons';
|
|
4
|
+
import { spawn, ElementProps } from './spawn';
|
|
5
|
+
import { updatable } from './update';
|
|
6
|
+
import '../components/Icon/Icon.scss';
|
|
7
|
+
|
|
8
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
9
|
+
|
|
10
|
+
export interface IconProps extends ElementProps {
|
|
11
|
+
/** Which icon (Foundations > Icons lists them all). */
|
|
12
|
+
name: IconName;
|
|
13
|
+
/** Width and height. Defaults to 1em: the icon is as big as the text around it. A number is pixels. */
|
|
14
|
+
size?: number | string;
|
|
15
|
+
/** Says what the icon means, for an icon that stands alone (screen readers read it). Leave it out when text beside it already says it. */
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Line thickness in grid units (the grid is 24). */
|
|
18
|
+
strokeWidth?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The <svg> Icon returns, with update() like every other component. */
|
|
22
|
+
export type IconElement = SVGSVGElement & { update(changes: Partial<IconProps>): IconElement };
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An icon from the NURVUS set, as an <svg> element: the same markup as the
|
|
26
|
+
* React Icon. 1em by default, in the text's color; decorative unless it has a
|
|
27
|
+
* label. icon.update({ name: 'check' }) swaps it for another.
|
|
28
|
+
*/
|
|
29
|
+
export default function Icon(props: IconProps): IconElement {
|
|
30
|
+
return updatable(({ name, size = '1em', label, strokeWidth = 2, className, ...rest }: IconProps) => spawn<any>({
|
|
31
|
+
tag: 'svg',
|
|
32
|
+
namespace: SVG,
|
|
33
|
+
className: classNames(className, 'icon', CONSTANT.CLASS_PREFIX),
|
|
34
|
+
'data-icon': name,
|
|
35
|
+
viewBox: '0 0 24 24',
|
|
36
|
+
width: size,
|
|
37
|
+
height: size,
|
|
38
|
+
fill: 'none',
|
|
39
|
+
stroke: 'currentColor',
|
|
40
|
+
'stroke-width': strokeWidth,
|
|
41
|
+
'stroke-linecap': 'round',
|
|
42
|
+
'stroke-linejoin': 'round',
|
|
43
|
+
...(label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true, focusable: 'false' }),
|
|
44
|
+
...rest,
|
|
45
|
+
children: iconNodes(name).map(([tag, attrs]) => spawn({ tag, namespace: SVG, ...attrs })),
|
|
46
|
+
}), props) as unknown as IconElement;
|
|
47
|
+
}
|
package/src/respawn/index.ts
CHANGED
|
@@ -39,6 +39,10 @@ export { default as Progress } from './Progress';
|
|
|
39
39
|
export type { ProgressProps, ProgressSize, ProgressStatus } from './Progress';
|
|
40
40
|
export { default as Layout } from './Layout';
|
|
41
41
|
export type { LayoutProps, Spacing, LegacySpacing } from './Layout';
|
|
42
|
+
export { default as Icon } from './Icon';
|
|
43
|
+
export type { IconProps, IconElement } from './Icon';
|
|
44
|
+
export { ICONS, ICON_NAMES } from '../icons';
|
|
45
|
+
export type { IconName, IconNode } from '../icons';
|
|
42
46
|
export { default as Tree } from './Tree';
|
|
43
47
|
export type { TreeProps, TreeItem } from './Tree';
|
|
44
48
|
export { default as Menu } from './Menu';
|
package/src/respawn/spawn.ts
CHANGED
|
@@ -46,9 +46,11 @@ export interface SpawnProps extends ElementProps {
|
|
|
46
46
|
children?: Child | ((el: HTMLElement) => void);
|
|
47
47
|
/** Appends the new element to this one. */
|
|
48
48
|
mountEl?: Element;
|
|
49
|
+
/** Makes the element in this namespace, e.g. 'http://www.w3.org/2000/svg' for SVG (Icon uses it). */
|
|
50
|
+
namespace?: string;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
const SKIP = new Set(['tag', 'children', 'className', 'events', 'style', 'mountEl', 'key', 'ref']);
|
|
53
|
+
const SKIP = new Set(['tag', 'children', 'className', 'events', 'style', 'mountEl', 'namespace', 'key', 'ref']);
|
|
52
54
|
const RENAME: Record<string, string> = { htmlFor: 'for', acceptCharset: 'accept-charset', httpEquiv: 'http-equiv' };
|
|
53
55
|
// Attributes whose value is the text "true" / "false" (React writes these as such).
|
|
54
56
|
const BOOLEANISH = new Set(['draggable', 'spellcheck', 'contenteditable']);
|
|
@@ -137,8 +139,8 @@ export function toNode(child: Child): Node {
|
|
|
137
139
|
*/
|
|
138
140
|
export function spawn<E extends HTMLElement = HTMLElement>(props: SpawnProps | HTMLElement = {}): E {
|
|
139
141
|
if (isNode(props)) return props as E;
|
|
140
|
-
const { tag = 'div', children, className, events, style, mountEl } = props;
|
|
141
|
-
const el = document.createElement(tag) as E;
|
|
142
|
+
const { tag = 'div', children, className, events, style, mountEl, namespace } = props;
|
|
143
|
+
const el = (namespace ? document.createElementNS(namespace, tag) : document.createElement(tag)) as E;
|
|
142
144
|
if (className) el.setAttribute('class', className);
|
|
143
145
|
Object.keys(props).forEach((key) => { if (!SKIP.has(key)) applyAttribute(el, key, props[key]); });
|
|
144
146
|
if (style) applyStyle(el, style);
|