@feitio/react 0.2.1 → 0.3.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/README.md +4 -2
- package/dist/Kanban.d.ts +40 -0
- package/dist/KanbanCard.d.ts +17 -0
- package/dist/actions/wire.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1125 -173
- package/package.json +3 -3
- package/src/Kanban.tsx +145 -0
- package/src/KanbanCard.tsx +54 -0
- package/src/actions/wire.ts +6 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feitio/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Feitio's components for React: the same HTML as the Astro components, with the behaviors wired by hooks.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"feitio",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"react": ">=19"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@feitio/core": "0.
|
|
46
|
+
"@feitio/core": "0.3.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@feitio/vanilla": "0.
|
|
49
|
+
"@feitio/vanilla": "0.3.0",
|
|
50
50
|
"@types/react": "19.3.0",
|
|
51
51
|
"@types/react-dom": "19.3.0",
|
|
52
52
|
"react": "19.3.1",
|
package/src/Kanban.tsx
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Children, type ReactElement, type ReactNode, useEffect, useRef } from 'react';
|
|
2
|
+
import { useElementBehavior } from './actions/use-element-behavior.ts';
|
|
3
|
+
import { wireKanban } from './actions/wire.ts';
|
|
4
|
+
import { Icon } from './Icon.tsx';
|
|
5
|
+
|
|
6
|
+
export interface KanbanColumn {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
/** What an empty column says, inviting to act. */
|
|
10
|
+
empty?: string;
|
|
11
|
+
/** The new-card button: its words, the field's label, and the words of Save and Cancel. */
|
|
12
|
+
create?: { label: string; field: string; save?: string; cancel?: string };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A move the board asks for: the card, from where, to where, and at which place. */
|
|
16
|
+
export interface KanbanMove {
|
|
17
|
+
id: string;
|
|
18
|
+
from: string;
|
|
19
|
+
to: string;
|
|
20
|
+
index: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface KanbanProps {
|
|
24
|
+
id: string;
|
|
25
|
+
/** The board's name, for screen readers. */
|
|
26
|
+
label: string;
|
|
27
|
+
columns: KanbanColumn[];
|
|
28
|
+
/** Each column's cards (KanbanCard), by column id. */
|
|
29
|
+
cards?: Record<string, ReactNode>;
|
|
30
|
+
/** The stage a phone shows first; the first column when left out. */
|
|
31
|
+
current?: string;
|
|
32
|
+
/** The title of the move list. */
|
|
33
|
+
moveLabel?: string;
|
|
34
|
+
/** A card was dragged or sent to another column: move it in your state. */
|
|
35
|
+
onMove?: (move: KanbanMove) => void;
|
|
36
|
+
/** Something was written in a column's new-card field: add the card. */
|
|
37
|
+
onCreate?: (column: string, text: string) => void;
|
|
38
|
+
sprite?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Kanban: work in columns, one per stage, and cards that go from one to the next. */
|
|
42
|
+
export function Kanban({
|
|
43
|
+
id,
|
|
44
|
+
label,
|
|
45
|
+
columns,
|
|
46
|
+
cards = {},
|
|
47
|
+
current,
|
|
48
|
+
moveLabel = 'Mover para',
|
|
49
|
+
onMove,
|
|
50
|
+
onCreate,
|
|
51
|
+
sprite,
|
|
52
|
+
}: KanbanProps): ReactElement {
|
|
53
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
54
|
+
useElementBehavior(ref, 'kanban', wireKanban);
|
|
55
|
+
const handlers = useRef({ onMove, onCreate });
|
|
56
|
+
handlers.current = { onMove, onCreate };
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const board = ref.current;
|
|
59
|
+
if (!board) return;
|
|
60
|
+
// React owns the cards: the board's own move is cancelled and the state moves them instead.
|
|
61
|
+
const move = (event: Event): void => {
|
|
62
|
+
const { onMove: handle } = handlers.current;
|
|
63
|
+
if (!handle) return;
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
const { id: card, from, to, index } = (event as CustomEvent<KanbanMove>).detail;
|
|
66
|
+
handle({ id: card, from, to, index });
|
|
67
|
+
};
|
|
68
|
+
const create = (event: Event): void => {
|
|
69
|
+
const { column, text } = (event as CustomEvent<{ column: string; text: string }>).detail;
|
|
70
|
+
handlers.current.onCreate?.(column, text);
|
|
71
|
+
};
|
|
72
|
+
board.addEventListener('feitio-kanban-move', move);
|
|
73
|
+
board.addEventListener('feitio-kanban-create', create);
|
|
74
|
+
return () => {
|
|
75
|
+
board.removeEventListener('feitio-kanban-move', move);
|
|
76
|
+
board.removeEventListener('feitio-kanban-create', create);
|
|
77
|
+
};
|
|
78
|
+
}, []);
|
|
79
|
+
const shown = current ?? columns[0]?.id;
|
|
80
|
+
const rendered = columns.map((c) => ({ ...c, n: Children.toArray(cards[c.id]).length }));
|
|
81
|
+
return (
|
|
82
|
+
<div className="feitio-kanban" id={id} data-move-label={moveLabel} ref={ref}>
|
|
83
|
+
<div className="feitio-kanban-scroll tabs-scroll">
|
|
84
|
+
<span className="edge start" aria-hidden="true" />
|
|
85
|
+
{/* biome-ignore lint/a11y/useSemanticElements: a group of toggle buttons, not a form. */}
|
|
86
|
+
<div className="tabs" role="group" aria-label={label}>
|
|
87
|
+
{rendered.map((c) => (
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
key={c.id}
|
|
91
|
+
data-col={c.id}
|
|
92
|
+
aria-pressed={c.id === shown ? 'true' : 'false'}
|
|
93
|
+
data-has={c.n ? '' : undefined}
|
|
94
|
+
>
|
|
95
|
+
{c.title} <span className="n">{c.n}</span>
|
|
96
|
+
</button>
|
|
97
|
+
))}
|
|
98
|
+
</div>
|
|
99
|
+
<span className="edge end" aria-hidden="true" />
|
|
100
|
+
</div>
|
|
101
|
+
<div className="feitio-kanban-scroll">
|
|
102
|
+
<span className="edge start" aria-hidden="true" />
|
|
103
|
+
<div className="cols">
|
|
104
|
+
{rendered.map((c) => (
|
|
105
|
+
// biome-ignore lint/a11y/useSemanticElements: a named group of cards, not a form; a section would make every column a landmark.
|
|
106
|
+
<div
|
|
107
|
+
className="col"
|
|
108
|
+
role="group"
|
|
109
|
+
key={c.id}
|
|
110
|
+
data-col={c.id}
|
|
111
|
+
aria-labelledby={`${id}-${c.id}`}
|
|
112
|
+
data-current={c.id === shown ? '' : undefined}
|
|
113
|
+
data-empty={c.n ? undefined : ''}
|
|
114
|
+
>
|
|
115
|
+
<div className="col-head">
|
|
116
|
+
<h3 id={`${id}-${c.id}`}>{c.title}</h3>
|
|
117
|
+
<span className="n">{c.n}</span>
|
|
118
|
+
</div>
|
|
119
|
+
{c.empty && (
|
|
120
|
+
<p className="empty" hidden={c.n > 0}>
|
|
121
|
+
{c.empty}
|
|
122
|
+
</p>
|
|
123
|
+
)}
|
|
124
|
+
{cards[c.id]}
|
|
125
|
+
{c.create && (
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
className="add"
|
|
129
|
+
data-field={c.create.field}
|
|
130
|
+
data-save={c.create.save ?? 'Salvar'}
|
|
131
|
+
data-cancel={c.create.cancel ?? 'Cancelar'}
|
|
132
|
+
>
|
|
133
|
+
<Icon name="plus" sprite={sprite} />
|
|
134
|
+
{c.create.label}
|
|
135
|
+
</button>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
))}
|
|
139
|
+
</div>
|
|
140
|
+
<span className="edge end" aria-hidden="true" />
|
|
141
|
+
</div>
|
|
142
|
+
<div className="minimap" aria-hidden="true" hidden />
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Icon } from './Icon.tsx';
|
|
3
|
+
|
|
4
|
+
export interface KanbanCardProps {
|
|
5
|
+
id: string;
|
|
6
|
+
/** The card's name, for screen readers (and the move button's label). */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The columns it may go to, by id. */
|
|
9
|
+
to?: string[];
|
|
10
|
+
/** The move button's word; screen readers hear it with the card's name. */
|
|
11
|
+
moveLabel?: string;
|
|
12
|
+
/** What a card that cannot move says. */
|
|
13
|
+
fixedLabel?: string;
|
|
14
|
+
sprite?: string;
|
|
15
|
+
/** The card's content, free. */
|
|
16
|
+
children?: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** KanbanCard: one card of a Kanban column, lifted paper held by a strip of tape. */
|
|
20
|
+
export function KanbanCard({
|
|
21
|
+
id,
|
|
22
|
+
name,
|
|
23
|
+
to = [],
|
|
24
|
+
moveLabel = 'Mover',
|
|
25
|
+
fixedLabel = 'fixo',
|
|
26
|
+
sprite,
|
|
27
|
+
children,
|
|
28
|
+
}: KanbanCardProps): ReactElement {
|
|
29
|
+
return (
|
|
30
|
+
<article
|
|
31
|
+
className="feitio-kanban-card"
|
|
32
|
+
data-id={id}
|
|
33
|
+
data-to={to.length ? to.join(' ') : undefined}
|
|
34
|
+
aria-label={name}
|
|
35
|
+
>
|
|
36
|
+
{children}
|
|
37
|
+
{to.length ? (
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
className="feitio-button move"
|
|
41
|
+
data-size="small"
|
|
42
|
+
aria-label={`${moveLabel}: ${name}`}
|
|
43
|
+
aria-haspopup="true"
|
|
44
|
+
aria-expanded="false"
|
|
45
|
+
>
|
|
46
|
+
{moveLabel}
|
|
47
|
+
<Icon name="chevron-down" sprite={sprite} />
|
|
48
|
+
</button>
|
|
49
|
+
) : (
|
|
50
|
+
<span className="fixed">{fixedLabel}</span>
|
|
51
|
+
)}
|
|
52
|
+
</article>
|
|
53
|
+
);
|
|
54
|
+
}
|
package/src/actions/wire.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dialogs } from '@feitio/vanilla/dialog/source';
|
|
2
2
|
import { forms } from '@feitio/vanilla/forms/source';
|
|
3
|
+
import { kanbans } from '@feitio/vanilla/kanban/source';
|
|
3
4
|
import { menus } from '@feitio/vanilla/menu/source';
|
|
4
5
|
import { scrolls } from '@feitio/vanilla/scroll/source';
|
|
5
6
|
import { noticeApi } from './notices.ts';
|
|
@@ -28,3 +29,8 @@ export function wireNotice(element: HTMLElement): void {
|
|
|
28
29
|
export function wireScroll(element: HTMLElement): void {
|
|
29
30
|
scrolls(window, element.parentElement ?? element);
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
/** One Kanban: its tabs, dragging, the move button and the new card. */
|
|
34
|
+
export function wireKanban(element: HTMLElement): void {
|
|
35
|
+
kanbans(window, element);
|
|
36
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,8 @@ export * from './Heading.tsx';
|
|
|
30
30
|
export * from './Hint.tsx';
|
|
31
31
|
export * from './Icon.tsx';
|
|
32
32
|
export * from './Inline.tsx';
|
|
33
|
+
export * from './Kanban.tsx';
|
|
34
|
+
export * from './KanbanCard.tsx';
|
|
33
35
|
export * from './Kbd.tsx';
|
|
34
36
|
export * from './Label.tsx';
|
|
35
37
|
export * from './Link.tsx';
|