@nocode-factory/sanity-kit 2.54.0 → 2.56.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 +23 -5
- package/dist/index.d.ts +48 -4
- package/dist/index.js +287 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useCollection.ts +19 -3
- package/src/lib/collectionQuery.ts +10 -2
- package/src/structure/collections.tsx +35 -5
- package/src/tools/collections/CollectionTable.tsx +257 -78
- package/src/tools/collections/CollectionToolbar.tsx +53 -4
- package/src/version.ts +1 -1
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import {Box, Button, Flex, Text, TextInput} from '@sanity/ui'
|
|
1
|
+
import {Box, Button, Card, Flex, Text, TextInput} from '@sanity/ui'
|
|
2
2
|
import {SearchIcon} from '@sanity/icons/Search'
|
|
3
3
|
import {DownloadIcon} from '@sanity/icons/Download'
|
|
4
4
|
import {RefreshIcon} from '@sanity/icons/Refresh'
|
|
5
|
+
import {AddIcon} from '@sanity/icons/Add'
|
|
6
|
+
import {ThLargeIcon} from '@sanity/icons/ThLarge'
|
|
7
|
+
import {UlistIcon} from '@sanity/icons/Ulist'
|
|
5
8
|
import {CollectionColumnPicker} from './CollectionColumnPicker'
|
|
6
9
|
import type {CollectionColumn} from '../../lib/collectionColumns'
|
|
7
10
|
|
|
11
|
+
/** Vue courante de la collection : liste compacte ou table. */
|
|
12
|
+
export type CollectionView = 'list' | 'table'
|
|
13
|
+
|
|
8
14
|
export interface CollectionToolbarProps {
|
|
15
|
+
view: CollectionView
|
|
16
|
+
onView: (view: CollectionView) => void
|
|
9
17
|
search: string
|
|
10
18
|
onSearch: (value: string) => void
|
|
11
19
|
columns: readonly CollectionColumn[]
|
|
@@ -13,17 +21,45 @@ export interface CollectionToolbarProps {
|
|
|
13
21
|
onToggleColumn: (key: string) => void
|
|
14
22
|
onExport: () => void
|
|
15
23
|
onRefresh: () => void
|
|
24
|
+
/** Création d'un item (template du niveau feuille appliqué par l'appelant). */
|
|
25
|
+
onCreate?: () => void
|
|
16
26
|
busy: boolean
|
|
17
27
|
/** Résumé « N items » ou « N of M ». */
|
|
18
28
|
summary: string
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
/** Barre au-dessus de la
|
|
31
|
+
/** Barre au-dessus de la collection : switch de vue, création, recherche, colonnes, export. */
|
|
22
32
|
export function CollectionToolbar(props: CollectionToolbarProps) {
|
|
23
|
-
const {search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, busy, summary} = props
|
|
33
|
+
const {view, onView, search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, onCreate, busy, summary} = props
|
|
24
34
|
|
|
25
35
|
return (
|
|
26
36
|
<Flex align="center" gap={2} wrap="wrap">
|
|
37
|
+
{/* Switch Liste / Table. */}
|
|
38
|
+
<Card radius={2} border style={{flex: 'none'}}>
|
|
39
|
+
<Flex>
|
|
40
|
+
<Button
|
|
41
|
+
mode={view === 'list' ? 'default' : 'bleed'}
|
|
42
|
+
tone={view === 'list' ? 'primary' : 'default'}
|
|
43
|
+
fontSize={1}
|
|
44
|
+
padding={2}
|
|
45
|
+
icon={UlistIcon}
|
|
46
|
+
title="List view"
|
|
47
|
+
aria-label="List view"
|
|
48
|
+
onClick={() => onView('list')}
|
|
49
|
+
/>
|
|
50
|
+
<Button
|
|
51
|
+
mode={view === 'table' ? 'default' : 'bleed'}
|
|
52
|
+
tone={view === 'table' ? 'primary' : 'default'}
|
|
53
|
+
fontSize={1}
|
|
54
|
+
padding={2}
|
|
55
|
+
icon={ThLargeIcon}
|
|
56
|
+
title="Table view"
|
|
57
|
+
aria-label="Table view"
|
|
58
|
+
onClick={() => onView('table')}
|
|
59
|
+
/>
|
|
60
|
+
</Flex>
|
|
61
|
+
</Card>
|
|
62
|
+
|
|
27
63
|
<Box style={{flex: 1, minWidth: 180}}>
|
|
28
64
|
<TextInput
|
|
29
65
|
icon={SearchIcon}
|
|
@@ -43,7 +79,20 @@ export function CollectionToolbar(props: CollectionToolbarProps) {
|
|
|
43
79
|
</Text>
|
|
44
80
|
|
|
45
81
|
<Flex gap={1} style={{flex: 'none'}}>
|
|
46
|
-
|
|
82
|
+
{onCreate && (
|
|
83
|
+
<Button
|
|
84
|
+
mode="ghost"
|
|
85
|
+
tone="primary"
|
|
86
|
+
fontSize={1}
|
|
87
|
+
padding={2}
|
|
88
|
+
icon={AddIcon}
|
|
89
|
+
text="New"
|
|
90
|
+
onClick={onCreate}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
{view === 'table' && (
|
|
94
|
+
<CollectionColumnPicker columns={columns} visible={visible} onToggle={onToggleColumn} />
|
|
95
|
+
)}
|
|
47
96
|
<Button
|
|
48
97
|
mode="bleed"
|
|
49
98
|
fontSize={1}
|
package/src/version.ts
CHANGED