@dxos/react-ui-stack 0.8.4-main.7ace549 → 0.8.4-main.8360d9e660
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/dist/lib/browser/index.mjs +743 -65
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +744 -65
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Stack/Stack.d.ts +5 -5
- package/dist/types/src/components/Stack/Stack.d.ts.map +1 -1
- package/dist/types/src/components/StackContext.d.ts +1 -1
- package/dist/types/src/components/StackContext.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/MenuSignifier.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItem.d.ts +7 -11
- package/dist/types/src/components/StackItem/StackItem.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItem.stories.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemContent.d.ts +2 -45
- package/dist/types/src/components/StackItem/StackItemContent.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemDragHandle.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemHeading.d.ts +1 -1
- package/dist/types/src/components/StackItem/StackItemHeading.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts +1 -1
- package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemSigil.d.ts +2 -2
- package/dist/types/src/components/StackItem/StackItemSigil.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/{defs.d.ts → types.d.ts} +1 -1
- package/dist/types/src/components/types.d.ts.map +1 -0
- package/dist/types/src/hooks/useStackDropForElements.d.ts +7 -5
- package/dist/types/src/hooks/useStackDropForElements.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +41 -38
- package/src/components/Stack/Stack.stories.tsx +2 -2
- package/src/components/Stack/Stack.tsx +13 -11
- package/src/components/StackContext.tsx +1 -1
- package/src/components/StackItem/MenuSignifier.tsx +2 -9
- package/src/components/StackItem/StackItem.stories.tsx +7 -5
- package/src/components/StackItem/StackItem.tsx +25 -13
- package/src/components/StackItem/StackItemContent.tsx +23 -54
- package/src/components/StackItem/StackItemDragHandle.tsx +4 -3
- package/src/components/StackItem/StackItemHeading.tsx +14 -13
- package/src/components/StackItem/StackItemResizeHandle.tsx +1 -1
- package/src/components/StackItem/StackItemSigil.tsx +8 -5
- package/src/components/index.ts +2 -2
- package/src/hooks/useStackDropForElements.ts +17 -10
- package/src/index.ts +0 -3
- package/src/playwright/playwright.config.ts +1 -1
- package/src/translations.ts +1 -1
- package/dist/lib/browser/chunk-3F2KBXLP.mjs +0 -1482
- package/dist/lib/browser/chunk-3F2KBXLP.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -31
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SYKFLQGK.mjs +0 -1484
- package/dist/lib/node-esm/chunk-SYKFLQGK.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -32
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/components/Image/Image.d.ts +0 -14
- package/dist/types/src/components/Image/Image.d.ts.map +0 -1
- package/dist/types/src/components/Image/Image.stories.d.ts +0 -33
- package/dist/types/src/components/Image/Image.stories.d.ts.map +0 -1
- package/dist/types/src/components/Image/index.d.ts +0 -2
- package/dist/types/src/components/Image/index.d.ts.map +0 -1
- package/dist/types/src/components/defs.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/LayoutControls.d.ts +0 -19
- package/dist/types/src/components/deprecated/LayoutControls.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/Card.d.ts +0 -69
- package/dist/types/src/exemplars/Card/Card.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/Card.stories.d.ts +0 -21
- package/dist/types/src/exemplars/Card/Card.stories.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/CardDragPreview.d.ts +0 -6
- package/dist/types/src/exemplars/Card/CardDragPreview.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/fragments.d.ts +0 -13
- package/dist/types/src/exemplars/Card/fragments.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/index.d.ts +0 -4
- package/dist/types/src/exemplars/Card/index.d.ts.map +0 -1
- package/dist/types/src/exemplars/CardStack/CardStack.d.ts +0 -42
- package/dist/types/src/exemplars/CardStack/CardStack.d.ts.map +0 -1
- package/dist/types/src/exemplars/CardStack/CardStack.stories.d.ts +0 -15
- package/dist/types/src/exemplars/CardStack/CardStack.stories.d.ts.map +0 -1
- package/dist/types/src/exemplars/CardStack/CardStackDragPreview.d.ts +0 -9
- package/dist/types/src/exemplars/CardStack/CardStackDragPreview.d.ts.map +0 -1
- package/dist/types/src/exemplars/CardStack/index.d.ts +0 -3
- package/dist/types/src/exemplars/CardStack/index.d.ts.map +0 -1
- package/dist/types/src/exemplars/index.d.ts +0 -3
- package/dist/types/src/exemplars/index.d.ts.map +0 -1
- package/dist/types/src/testing/CardContainer.d.ts +0 -6
- package/dist/types/src/testing/CardContainer.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/src/components/Image/Image.stories.tsx +0 -84
- package/src/components/Image/Image.tsx +0 -222
- package/src/components/Image/index.ts +0 -5
- package/src/components/deprecated/LayoutControls.tsx +0 -109
- package/src/exemplars/Card/Card.stories.tsx +0 -64
- package/src/exemplars/Card/Card.tsx +0 -210
- package/src/exemplars/Card/CardDragPreview.tsx +0 -22
- package/src/exemplars/Card/fragments.ts +0 -24
- package/src/exemplars/Card/index.ts +0 -7
- package/src/exemplars/CardStack/CardStack.stories.tsx +0 -173
- package/src/exemplars/CardStack/CardStack.tsx +0 -139
- package/src/exemplars/CardStack/CardStackDragPreview.tsx +0 -61
- package/src/exemplars/CardStack/index.ts +0 -6
- package/src/exemplars/index.ts +0 -6
- package/src/testing/CardContainer.tsx +0 -37
- package/src/testing/index.ts +0 -5
- /package/src/components/{defs.ts → types.ts} +0 -0
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Primitive } from '@radix-ui/react-primitive';
|
|
6
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
7
|
-
import React, {
|
|
8
|
-
type ComponentPropsWithRef,
|
|
9
|
-
type ComponentPropsWithoutRef,
|
|
10
|
-
type FC,
|
|
11
|
-
type PropsWithChildren,
|
|
12
|
-
forwardRef,
|
|
13
|
-
} from 'react';
|
|
14
|
-
|
|
15
|
-
import { Icon, IconButton, type ThemedClassName, Toolbar, type ToolbarRootProps, useTranslation } from '@dxos/react-ui';
|
|
16
|
-
import { cardMinInlineSize, hoverableControls, mx } from '@dxos/react-ui-theme';
|
|
17
|
-
|
|
18
|
-
import { Image, StackItem } from '../../components';
|
|
19
|
-
import { translationKey } from '../../translations';
|
|
20
|
-
|
|
21
|
-
import { cardChrome, cardHeading, cardRoot, cardSpacing, cardText } from './fragments';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The default width of cards. It should be no larger than 320px per WCAG 2.1 SC 1.4.10.
|
|
25
|
-
*/
|
|
26
|
-
const cardDefaultInlineSize = cardMinInlineSize;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* This is `cardDefaultInlineSize` plus 2 times the sum of the inner and outer spacing applied by CardStack on the inline axis.
|
|
30
|
-
*/
|
|
31
|
-
const cardStackDefaultInlineSizeRem = cardDefaultInlineSize + 2.125;
|
|
32
|
-
|
|
33
|
-
type SharedCardProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { asChild?: boolean };
|
|
34
|
-
|
|
35
|
-
const CardStaticRoot = forwardRef<HTMLDivElement, SharedCardProps & { id?: string }>(
|
|
36
|
-
({ children, classNames, id, asChild, role = 'group', ...props }, forwardedRef) => {
|
|
37
|
-
const Root = asChild ? Slot : 'div';
|
|
38
|
-
const rootProps = asChild ? { classNames: [cardRoot, classNames] } : { className: mx(cardRoot, classNames), role };
|
|
39
|
-
return (
|
|
40
|
-
<Root {...(id && { 'data-object-id': id })} {...props} {...rootProps} ref={forwardedRef}>
|
|
41
|
-
{children}
|
|
42
|
-
</Root>
|
|
43
|
-
);
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* This should be used by Surface fulfillments in cases where the content may or may not already be encapsulated (e.g., in a Popover) and knows this based on the `role` it receives.
|
|
49
|
-
* This will render a `Card.StaticRoot` by default, otherwise it will render a `div` primitive with the appropriate styling for specific handled situations.
|
|
50
|
-
*/
|
|
51
|
-
const CardSurfaceRoot = ({
|
|
52
|
-
id,
|
|
53
|
-
role = 'never',
|
|
54
|
-
children,
|
|
55
|
-
classNames,
|
|
56
|
-
}: ThemedClassName<PropsWithChildren<{ id?: string; role?: string }>>) => {
|
|
57
|
-
if (['card--popover', 'card--intrinsic', 'card--extrinsic'].includes(role)) {
|
|
58
|
-
return (
|
|
59
|
-
<div
|
|
60
|
-
{...(id && { 'data-object-id': id })}
|
|
61
|
-
className={mx(
|
|
62
|
-
role === 'card--popover'
|
|
63
|
-
? 'popover-card-width'
|
|
64
|
-
: ['card--intrinsic', 'card--extrinsic'].includes(role)
|
|
65
|
-
? 'contents'
|
|
66
|
-
: '',
|
|
67
|
-
classNames,
|
|
68
|
-
)}
|
|
69
|
-
>
|
|
70
|
-
{children}
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
} else {
|
|
74
|
-
return (
|
|
75
|
-
<CardStaticRoot
|
|
76
|
-
id={id}
|
|
77
|
-
classNames={[
|
|
78
|
-
role === 'card--transclusion' && 'mlb-1',
|
|
79
|
-
role === 'card--transclusion' && hoverableControls,
|
|
80
|
-
classNames,
|
|
81
|
-
]}
|
|
82
|
-
>
|
|
83
|
-
{children}
|
|
84
|
-
</CardStaticRoot>
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const CardHeading = forwardRef<HTMLDivElement, SharedCardProps>(
|
|
90
|
-
({ children, classNames, asChild, role = 'heading', ...props }, forwardedRef) => {
|
|
91
|
-
const Root = asChild ? Slot : 'div';
|
|
92
|
-
const rootProps = asChild
|
|
93
|
-
? { classNames: [cardHeading, cardText, classNames] }
|
|
94
|
-
: { className: mx(cardHeading, cardText, classNames), role };
|
|
95
|
-
return (
|
|
96
|
-
<Root {...props} {...rootProps} ref={forwardedRef}>
|
|
97
|
-
{children}
|
|
98
|
-
</Root>
|
|
99
|
-
);
|
|
100
|
-
},
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
const CardToolbar = forwardRef<HTMLDivElement, ToolbarRootProps>(({ children, classNames, ...props }, forwardedRef) => {
|
|
104
|
-
return (
|
|
105
|
-
<Toolbar.Root {...props} classNames={['bg-transparent density-coarse', classNames]} ref={forwardedRef}>
|
|
106
|
-
{children}
|
|
107
|
-
</Toolbar.Root>
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const CardToolbarIconButton = Toolbar.IconButton;
|
|
112
|
-
const CardToolbarSeparator = Toolbar.Separator;
|
|
113
|
-
|
|
114
|
-
const CardDragHandle = forwardRef<HTMLButtonElement, { toolbarItem?: boolean }>(({ toolbarItem }, forwardedRef) => {
|
|
115
|
-
const { t } = useTranslation(translationKey);
|
|
116
|
-
const Root = toolbarItem ? Toolbar.IconButton : IconButton;
|
|
117
|
-
return (
|
|
118
|
-
<Root
|
|
119
|
-
iconOnly
|
|
120
|
-
icon='ph--dots-six-vertical--regular'
|
|
121
|
-
variant='ghost'
|
|
122
|
-
label={t('drag handle label')}
|
|
123
|
-
classNames='pli-2'
|
|
124
|
-
ref={forwardedRef}
|
|
125
|
-
/>
|
|
126
|
-
);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const CardDragPreview = StackItem.DragPreview;
|
|
130
|
-
|
|
131
|
-
const CardMenu = Primitive.div as FC<ComponentPropsWithRef<'div'>>;
|
|
132
|
-
|
|
133
|
-
type CardPosterProps = ThemedClassName<
|
|
134
|
-
{
|
|
135
|
-
alt: string;
|
|
136
|
-
aspect?: 'video' | 'auto';
|
|
137
|
-
} & Partial<{ image: string; icon: string }>
|
|
138
|
-
>;
|
|
139
|
-
|
|
140
|
-
const CardPoster = (props: CardPosterProps) => {
|
|
141
|
-
const aspect = props.aspect === 'auto' ? 'aspect-auto' : 'aspect-video';
|
|
142
|
-
if (props.image) {
|
|
143
|
-
return (
|
|
144
|
-
<Image classNames={[`dx-card__poster is-full`, aspect, props.classNames]} src={props.image} alt={props.alt} />
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (props.icon) {
|
|
149
|
-
return (
|
|
150
|
-
<div
|
|
151
|
-
role='image'
|
|
152
|
-
className={mx(`dx-card__poster grid place-items-center bg-inputSurface text-subdued`, aspect, props.classNames)}
|
|
153
|
-
aria-label={props.alt}
|
|
154
|
-
>
|
|
155
|
-
<Icon icon={props.icon} size={10} />
|
|
156
|
-
</div>
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const CardChrome = forwardRef<HTMLDivElement, SharedCardProps>(
|
|
162
|
-
({ children, classNames, asChild, role = 'none', ...props }, forwardedRef) => {
|
|
163
|
-
const Root = asChild ? Slot : 'div';
|
|
164
|
-
const rootProps = asChild
|
|
165
|
-
? { classNames: [cardChrome, classNames] }
|
|
166
|
-
: { className: mx(cardChrome, classNames), role };
|
|
167
|
-
return (
|
|
168
|
-
<Root {...props} {...rootProps} ref={forwardedRef}>
|
|
169
|
-
{children}
|
|
170
|
-
</Root>
|
|
171
|
-
);
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
const CardText = forwardRef<HTMLDivElement, SharedCardProps>(
|
|
176
|
-
({ children, classNames, asChild, role = 'none', ...props }, forwardedRef) => {
|
|
177
|
-
const Root = asChild ? Slot : 'div';
|
|
178
|
-
const rootProps = asChild ? { classNames: [cardText, classNames] } : { className: mx(cardText, classNames), role };
|
|
179
|
-
return (
|
|
180
|
-
<Root {...props} {...rootProps} ref={forwardedRef}>
|
|
181
|
-
{children}
|
|
182
|
-
</Root>
|
|
183
|
-
);
|
|
184
|
-
},
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
export const Card = {
|
|
188
|
-
StaticRoot: CardStaticRoot,
|
|
189
|
-
SurfaceRoot: CardSurfaceRoot,
|
|
190
|
-
Heading: CardHeading,
|
|
191
|
-
Toolbar: CardToolbar,
|
|
192
|
-
ToolbarIconButton: CardToolbarIconButton,
|
|
193
|
-
ToolbarSeparator: CardToolbarSeparator,
|
|
194
|
-
DragHandle: CardDragHandle,
|
|
195
|
-
DragPreview: CardDragPreview,
|
|
196
|
-
Menu: CardMenu,
|
|
197
|
-
Poster: CardPoster,
|
|
198
|
-
Chrome: CardChrome,
|
|
199
|
-
Text: CardText,
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
export {
|
|
203
|
-
cardRoot,
|
|
204
|
-
cardHeading,
|
|
205
|
-
cardText,
|
|
206
|
-
cardChrome,
|
|
207
|
-
cardSpacing,
|
|
208
|
-
cardStackDefaultInlineSizeRem,
|
|
209
|
-
cardDefaultInlineSize,
|
|
210
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { type PropsWithChildren } from 'react';
|
|
6
|
-
|
|
7
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
8
|
-
|
|
9
|
-
import { cardRoot } from './fragments';
|
|
10
|
-
|
|
11
|
-
const CardDragPreviewRoot = ({ children }: PropsWithChildren<{}>) => {
|
|
12
|
-
return <div className='p-2'>{children}</div>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const CardDragPreviewContent = ({ children }: PropsWithChildren<{}>) => {
|
|
16
|
-
return <div className={mx(cardRoot, 'ring-focusLine ring-neutralFocusIndicator')}>{children}</div>;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const CardDragPreview = {
|
|
20
|
-
Root: CardDragPreviewRoot,
|
|
21
|
-
Content: CardDragPreviewContent,
|
|
22
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
export const cardRoot =
|
|
6
|
-
'rounded overflow-hidden bg-cardSurface border border-separator dark:border-subduedSeparator dx-focus-ring-group-y-indicator relative min-bs-[--rail-item] group/card';
|
|
7
|
-
|
|
8
|
-
export const cardSpacing = 'pli-cardSpacingInline mlb-cardSpacingBlock';
|
|
9
|
-
export const cardNoSpacing = 'pli-0 mlb-0';
|
|
10
|
-
export const labelSpacing = 'mbs-inputSpacingBlock mbe-labelSpacingBlock';
|
|
11
|
-
|
|
12
|
-
export const cardDialogContent = 'p-0 bs-content min-bs-[8rem] max-bs-full md:max-is-[32rem] overflow-hidden';
|
|
13
|
-
export const cardDialogHeader = 'pli-cardSpacingInline mbs-cardSpacingBlock flex justify-between';
|
|
14
|
-
export const cardDialogOverflow = 'overflow-y-auto min-bs-0 flex-1';
|
|
15
|
-
export const cardDialogPaddedOverflow = `${cardDialogOverflow} plb-cardSpacingBlock`;
|
|
16
|
-
export const cardDialogSearchListRoot =
|
|
17
|
-
'pli-cardSpacingInline pbs-cardSpacingBlock [&>input]:mbe-0 min-bs-0 flex-1 flex flex-col';
|
|
18
|
-
|
|
19
|
-
export const cardText = cardSpacing;
|
|
20
|
-
|
|
21
|
-
export const cardHeading = 'text-lg font-medium line-clamp-2 grow';
|
|
22
|
-
|
|
23
|
-
export const cardChrome =
|
|
24
|
-
'pli-[--dx-cardSpacingChrome] mlb-[--dx-cardSpacingChrome] [&_.dx-button]:text-start [&_.dx-button]:is-full [&_.dx-button]:pis-[calc(var(--dx-cardSpacingInline)-var(--dx-cardSpacingChrome))]';
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
|
|
6
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
-
import React, { useCallback, useState } from 'react';
|
|
8
|
-
|
|
9
|
-
import { faker } from '@dxos/random';
|
|
10
|
-
import { IconButton } from '@dxos/react-ui';
|
|
11
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
12
|
-
|
|
13
|
-
import { StackItem } from '../../components';
|
|
14
|
-
import { Card, CardDragPreview } from '../Card';
|
|
15
|
-
|
|
16
|
-
import { CardStack } from './CardStack';
|
|
17
|
-
|
|
18
|
-
faker.seed(0);
|
|
19
|
-
|
|
20
|
-
type CardItem = {
|
|
21
|
-
id: string;
|
|
22
|
-
title: string;
|
|
23
|
-
description: string;
|
|
24
|
-
image: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type StackItemData = {
|
|
28
|
-
id: string;
|
|
29
|
-
type?: 'column' | 'card';
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const CardStackStory = () => {
|
|
33
|
-
const [column, setColumn] = useState<CardItem[]>(
|
|
34
|
-
faker.helpers.multiple(
|
|
35
|
-
() => ({
|
|
36
|
-
id: faker.string.uuid(),
|
|
37
|
-
title: faker.commerce.productName(),
|
|
38
|
-
description: faker.lorem.paragraph(),
|
|
39
|
-
image: faker.image.url(),
|
|
40
|
-
}),
|
|
41
|
-
{ count: 12 },
|
|
42
|
-
),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const handleRearrange = useCallback((source: StackItemData, target: StackItemData, closestEdge: Edge | null) => {
|
|
46
|
-
setColumn((prevColumn) => {
|
|
47
|
-
const newColumns = [...prevColumn];
|
|
48
|
-
// Reordering cards within a column
|
|
49
|
-
const sourceCardIndex = prevColumn.findIndex((card) => card.id === source.id);
|
|
50
|
-
const targetCardIndex = prevColumn.findIndex((card) => card.id === target.id);
|
|
51
|
-
|
|
52
|
-
if (typeof sourceCardIndex === 'number' && typeof targetCardIndex === 'number') {
|
|
53
|
-
const [movedCard] = newColumns.splice(sourceCardIndex, 1);
|
|
54
|
-
|
|
55
|
-
let insertIndex;
|
|
56
|
-
if (sourceCardIndex < targetCardIndex) {
|
|
57
|
-
insertIndex = closestEdge === 'bottom' ? targetCardIndex : targetCardIndex - 1;
|
|
58
|
-
} else {
|
|
59
|
-
insertIndex = closestEdge === 'bottom' ? targetCardIndex + 1 : targetCardIndex;
|
|
60
|
-
}
|
|
61
|
-
newColumns.splice(insertIndex, 0, movedCard);
|
|
62
|
-
}
|
|
63
|
-
return newColumns;
|
|
64
|
-
});
|
|
65
|
-
}, []);
|
|
66
|
-
|
|
67
|
-
const handleAddCard = useCallback(() => {
|
|
68
|
-
setColumn((prevColumn) => {
|
|
69
|
-
const newColumn = [...prevColumn];
|
|
70
|
-
const newCard = {
|
|
71
|
-
id: faker.string.uuid(),
|
|
72
|
-
title: faker.commerce.productName(),
|
|
73
|
-
description: faker.lorem.paragraph(),
|
|
74
|
-
image: faker.image.url(),
|
|
75
|
-
} satisfies CardItem;
|
|
76
|
-
newColumn.push(newCard);
|
|
77
|
-
console.log('[add card]', prevColumn.length, newColumn.length);
|
|
78
|
-
return newColumn;
|
|
79
|
-
});
|
|
80
|
-
}, []);
|
|
81
|
-
|
|
82
|
-
const handleRemoveCard = useCallback((cardId: string) => {
|
|
83
|
-
setColumn((prevColumn) => {
|
|
84
|
-
const newColumn = [...prevColumn];
|
|
85
|
-
|
|
86
|
-
const cardIndex = prevColumn.findIndex((card) => card.id === cardId);
|
|
87
|
-
if (cardIndex !== -1) {
|
|
88
|
-
newColumn.splice(cardIndex, 1);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return newColumn;
|
|
92
|
-
});
|
|
93
|
-
}, []);
|
|
94
|
-
|
|
95
|
-
return (
|
|
96
|
-
<CardStack.Root classNames='is-96'>
|
|
97
|
-
<CardStack.Content>
|
|
98
|
-
<CardStack.Stack id='story column' onRearrange={handleRearrange} itemsCount={column.length}>
|
|
99
|
-
{column.map((card, cardIndex, cardsArray) => {
|
|
100
|
-
const cardItem = { id: card.id, type: 'card' as const };
|
|
101
|
-
const prevCardId = cardIndex > 0 ? cardsArray[cardIndex - 1].id : undefined;
|
|
102
|
-
const nextCardId = cardIndex < cardsArray.length - 1 ? cardsArray[cardIndex + 1].id : undefined;
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<CardStack.Item asChild key={card.id}>
|
|
106
|
-
<StackItem.Root
|
|
107
|
-
item={cardItem}
|
|
108
|
-
focusIndicatorVariant='group'
|
|
109
|
-
prevSiblingId={prevCardId}
|
|
110
|
-
nextSiblingId={nextCardId}
|
|
111
|
-
>
|
|
112
|
-
<Card.StaticRoot>
|
|
113
|
-
<Card.Toolbar>
|
|
114
|
-
<StackItem.DragHandle asChild>
|
|
115
|
-
<Card.DragHandle toolbarItem />
|
|
116
|
-
</StackItem.DragHandle>
|
|
117
|
-
<Card.ToolbarSeparator variant='gap' />
|
|
118
|
-
<Card.ToolbarIconButton
|
|
119
|
-
iconOnly
|
|
120
|
-
variant='ghost'
|
|
121
|
-
icon='ph--x--regular'
|
|
122
|
-
label='Remove card'
|
|
123
|
-
onClick={() => handleRemoveCard(card.id)}
|
|
124
|
-
/>
|
|
125
|
-
</Card.Toolbar>
|
|
126
|
-
<Card.Poster alt={card.title} image={card.image} />
|
|
127
|
-
<Card.Heading>{card.title}</Card.Heading>
|
|
128
|
-
<Card.Text classNames='line-clamp-2'>{card.description}</Card.Text>
|
|
129
|
-
</Card.StaticRoot>
|
|
130
|
-
<StackItem.DragPreview>
|
|
131
|
-
{() => (
|
|
132
|
-
<CardDragPreview.Root>
|
|
133
|
-
<CardDragPreview.Content>
|
|
134
|
-
<Card.Toolbar>
|
|
135
|
-
<Card.DragHandle toolbarItem />
|
|
136
|
-
</Card.Toolbar>
|
|
137
|
-
<Card.Poster alt={card.title} image={card.image} />
|
|
138
|
-
<Card.Heading>{card.title}</Card.Heading>
|
|
139
|
-
<Card.Text classNames='line-clamp-2'>{card.description}</Card.Text>
|
|
140
|
-
</CardDragPreview.Content>
|
|
141
|
-
</CardDragPreview.Root>
|
|
142
|
-
)}
|
|
143
|
-
</StackItem.DragPreview>
|
|
144
|
-
</StackItem.Root>
|
|
145
|
-
</CardStack.Item>
|
|
146
|
-
);
|
|
147
|
-
})}
|
|
148
|
-
</CardStack.Stack>
|
|
149
|
-
|
|
150
|
-
<CardStack.Footer>
|
|
151
|
-
<IconButton icon='ph--plus--regular' label='Add card' onClick={handleAddCard} classNames='is-full' />
|
|
152
|
-
</CardStack.Footer>
|
|
153
|
-
|
|
154
|
-
<CardStack.Heading>{faker.company.name()}</CardStack.Heading>
|
|
155
|
-
</CardStack.Content>
|
|
156
|
-
</CardStack.Root>
|
|
157
|
-
);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const meta = {
|
|
161
|
-
title: 'ui/react-ui-stack/CardStack',
|
|
162
|
-
component: CardStackStory,
|
|
163
|
-
decorators: [withTheme],
|
|
164
|
-
parameters: {
|
|
165
|
-
layout: 'fullscreen',
|
|
166
|
-
},
|
|
167
|
-
} satisfies Meta<typeof CardStackStory>;
|
|
168
|
-
|
|
169
|
-
export default meta;
|
|
170
|
-
|
|
171
|
-
type Story = StoryObj<typeof CardStackStory>;
|
|
172
|
-
|
|
173
|
-
export const Default: Story = {};
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
6
|
-
import React, { type ComponentPropsWithoutRef, forwardRef } from 'react';
|
|
7
|
-
|
|
8
|
-
import type { ThemedClassName } from '@dxos/react-ui';
|
|
9
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
10
|
-
|
|
11
|
-
import { Stack, type StackProps, railGridHorizontalContainFitContent } from '../../components';
|
|
12
|
-
import { Card } from '../Card';
|
|
13
|
-
|
|
14
|
-
type SharedCardStackProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { asChild?: boolean };
|
|
15
|
-
|
|
16
|
-
const CardStackStack = forwardRef<
|
|
17
|
-
HTMLDivElement,
|
|
18
|
-
Omit<StackProps, 'orientation' | 'size' | 'rail' | 'separatorOnScroll'>
|
|
19
|
-
>(({ children, classNames, itemsCount = 0, ...props }, forwardedRef) => {
|
|
20
|
-
return (
|
|
21
|
-
<Stack
|
|
22
|
-
orientation='vertical'
|
|
23
|
-
size='contain'
|
|
24
|
-
rail={false}
|
|
25
|
-
classNames={
|
|
26
|
-
/* NOTE(thure): Do not let this element have zero intrinsic size, otherwise the drop indicator will not display. See #9035. */
|
|
27
|
-
['plb-1', itemsCount > 0 && 'plb-2', classNames]
|
|
28
|
-
}
|
|
29
|
-
itemsCount={itemsCount}
|
|
30
|
-
separatorOnScroll={9}
|
|
31
|
-
data-density='fine'
|
|
32
|
-
{...props}
|
|
33
|
-
ref={forwardedRef}
|
|
34
|
-
>
|
|
35
|
-
{children}
|
|
36
|
-
</Stack>
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const CardStackDragHandle = Card.DragHandle;
|
|
41
|
-
|
|
42
|
-
const cardStackHeading = 'mli-2 order-first bg-transparent rounded-bs-md flex items-center';
|
|
43
|
-
|
|
44
|
-
const CardStackHeading = forwardRef<HTMLDivElement, SharedCardStackProps>(
|
|
45
|
-
({ children, classNames, asChild, role = 'heading', ...props }, forwardedRef) => {
|
|
46
|
-
const Root = asChild ? Slot : 'div';
|
|
47
|
-
const rootProps = asChild
|
|
48
|
-
? { classNames: [cardStackHeading, classNames] }
|
|
49
|
-
: { className: mx(cardStackHeading, classNames), role };
|
|
50
|
-
return (
|
|
51
|
-
<Root {...props} {...rootProps} ref={forwardedRef}>
|
|
52
|
-
{children}
|
|
53
|
-
</Root>
|
|
54
|
-
);
|
|
55
|
-
},
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const cardStackFooter =
|
|
59
|
-
'plb-2 mli-2 border-bs border-transparent [[data-scroll-separator-end="true"]_&]:border-subduedSeparator';
|
|
60
|
-
|
|
61
|
-
const CardStackFooter = forwardRef<HTMLDivElement, SharedCardStackProps>(
|
|
62
|
-
({ children, classNames, asChild, role = 'none', ...props }, forwardedRef) => {
|
|
63
|
-
const Root = asChild ? Slot : 'div';
|
|
64
|
-
const rootProps = asChild
|
|
65
|
-
? { classNames: [cardStackFooter, classNames] }
|
|
66
|
-
: { className: mx(cardStackFooter, classNames), role };
|
|
67
|
-
return (
|
|
68
|
-
<Root {...props} {...rootProps} ref={forwardedRef}>
|
|
69
|
-
{children}
|
|
70
|
-
</Root>
|
|
71
|
-
);
|
|
72
|
-
},
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const cardStackContent =
|
|
76
|
-
'shrink min-bs-0 bg-baseSurface border border-separator rounded-md grid dx-focus-ring-group-x-indicator kanban-drop';
|
|
77
|
-
|
|
78
|
-
type CardStackContentProps = SharedCardStackProps & {
|
|
79
|
-
footer?: boolean;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const CardStackContent = forwardRef<HTMLDivElement, CardStackContentProps>(
|
|
83
|
-
({ children, classNames, asChild, role = 'none', footer = true, ...props }, forwardedRef) => {
|
|
84
|
-
const Root = asChild ? Slot : 'div';
|
|
85
|
-
const baseClassNames = footer ? [cardStackContent, railGridHorizontalContainFitContent] : [cardStackContent];
|
|
86
|
-
const rootProps = asChild
|
|
87
|
-
? { classNames: [...baseClassNames, classNames] }
|
|
88
|
-
: { className: mx(...baseClassNames, classNames), role };
|
|
89
|
-
return (
|
|
90
|
-
<Root {...props} {...rootProps} data-scroll-separator='false' ref={forwardedRef}>
|
|
91
|
-
{children}
|
|
92
|
-
</Root>
|
|
93
|
-
);
|
|
94
|
-
},
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
const cardStackRoot = 'flex flex-col pli-2 plb-2';
|
|
98
|
-
|
|
99
|
-
const CardStackRoot = forwardRef<HTMLDivElement, SharedCardStackProps>(
|
|
100
|
-
({ children, classNames, asChild, role = 'none', ...props }, forwardedRef) => {
|
|
101
|
-
const Root = asChild ? Slot : 'div';
|
|
102
|
-
const rootProps = asChild
|
|
103
|
-
? { classNames: [cardStackRoot, classNames] }
|
|
104
|
-
: { className: mx(cardStackRoot, classNames), role };
|
|
105
|
-
return (
|
|
106
|
-
<Root {...props} {...rootProps} ref={forwardedRef}>
|
|
107
|
-
{children}
|
|
108
|
-
</Root>
|
|
109
|
-
);
|
|
110
|
-
},
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const cardStackItem = 'contain-layout pli-2 plb-1 first-of-type:pbs-0 last-of-type:pbe-0';
|
|
114
|
-
|
|
115
|
-
const CardStackItem = forwardRef<HTMLDivElement, SharedCardStackProps>(
|
|
116
|
-
({ children, classNames, asChild, role = 'none', ...props }, forwardedRef) => {
|
|
117
|
-
const Root = asChild ? Slot : 'div';
|
|
118
|
-
const rootProps = asChild
|
|
119
|
-
? { classNames: [cardStackItem, classNames] }
|
|
120
|
-
: { className: mx(cardStackItem, classNames), role };
|
|
121
|
-
return (
|
|
122
|
-
<Root {...props} {...rootProps} ref={forwardedRef}>
|
|
123
|
-
{children}
|
|
124
|
-
</Root>
|
|
125
|
-
);
|
|
126
|
-
},
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
export const CardStack = {
|
|
130
|
-
Root: CardStackRoot,
|
|
131
|
-
Content: CardStackContent,
|
|
132
|
-
Stack: CardStackStack,
|
|
133
|
-
Heading: CardStackHeading,
|
|
134
|
-
Footer: CardStackFooter,
|
|
135
|
-
DragHandle: CardStackDragHandle,
|
|
136
|
-
Item: CardStackItem,
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export { cardStackRoot, cardStackFooter, cardStackHeading, cardStackContent, cardStackItem };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { type PropsWithChildren } from 'react';
|
|
6
|
-
|
|
7
|
-
import { IconButton, useTranslation } from '@dxos/react-ui';
|
|
8
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
9
|
-
|
|
10
|
-
import { type StackProps } from '../../components';
|
|
11
|
-
import { translationKey } from '../../translations';
|
|
12
|
-
|
|
13
|
-
const CardStackDragPreviewRoot = ({ children }: PropsWithChildren<{}>) => {
|
|
14
|
-
return (
|
|
15
|
-
<div className='p-2'>
|
|
16
|
-
<div className='rounded-md max-bs-[calc(100dvh-1rem)] overflow-hidden bg-baseSurface border border-separator ring-focusLine ring-neutralFocusIndicator flex flex-col'>
|
|
17
|
-
{children}
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const CardStackDragPreviewHeading = ({ children }: PropsWithChildren<{}>) => {
|
|
24
|
-
const { t } = useTranslation(translationKey);
|
|
25
|
-
return (
|
|
26
|
-
<div className='flex items-center p-2'>
|
|
27
|
-
<IconButton
|
|
28
|
-
iconOnly
|
|
29
|
-
icon='ph--dots-six-vertical--regular'
|
|
30
|
-
variant='ghost'
|
|
31
|
-
label={t('column drag handle label')}
|
|
32
|
-
classNames='pli-2'
|
|
33
|
-
/>
|
|
34
|
-
{children}
|
|
35
|
-
</div>
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const CardStackDragPreviewContent = ({
|
|
40
|
-
children,
|
|
41
|
-
itemsCount = 0,
|
|
42
|
-
}: PropsWithChildren<Pick<StackProps, 'itemsCount'>>) => {
|
|
43
|
-
return (
|
|
44
|
-
<div
|
|
45
|
-
className={mx('overflow-y-auto flex-1 pli-2 flex flex-col gap-2', 'plb-1', itemsCount > 0 ? 'plb-2' : 'plb-1')}
|
|
46
|
-
>
|
|
47
|
-
{children}
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const CardStackDragPreviewFooter = ({ children }: PropsWithChildren<{}>) => {
|
|
53
|
-
return <div className='p-2 border-t border-separator'>{children}</div>;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const CardStackDragPreview = {
|
|
57
|
-
Root: CardStackDragPreviewRoot,
|
|
58
|
-
Heading: CardStackDragPreviewHeading,
|
|
59
|
-
Content: CardStackDragPreviewContent,
|
|
60
|
-
Footer: CardStackDragPreviewFooter,
|
|
61
|
-
};
|
package/src/exemplars/index.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { type PropsWithChildren } from 'react';
|
|
6
|
-
|
|
7
|
-
import { ExtrinsicCardContainer, IntrinsicCardContainer, PopoverCardContainer } from '@dxos/storybook-utils';
|
|
8
|
-
|
|
9
|
-
import { Card } from '../exemplars';
|
|
10
|
-
|
|
11
|
-
export const CardContainer = ({
|
|
12
|
-
children,
|
|
13
|
-
icon = 'ph--placeholder--regular',
|
|
14
|
-
role,
|
|
15
|
-
}: PropsWithChildren<{ icon?: string; role?: string }>) => {
|
|
16
|
-
switch (role) {
|
|
17
|
-
case 'card--popover':
|
|
18
|
-
return <PopoverCardContainer icon={icon}>{children}</PopoverCardContainer>;
|
|
19
|
-
|
|
20
|
-
case 'card--extrinsic':
|
|
21
|
-
return (
|
|
22
|
-
<ExtrinsicCardContainer>
|
|
23
|
-
<Card.StaticRoot>{children}</Card.StaticRoot>
|
|
24
|
-
</ExtrinsicCardContainer>
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
case 'card--intrinsic':
|
|
28
|
-
return (
|
|
29
|
-
<IntrinsicCardContainer>
|
|
30
|
-
<Card.StaticRoot>{children}</Card.StaticRoot>
|
|
31
|
-
</IntrinsicCardContainer>
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
default:
|
|
35
|
-
return <Card.StaticRoot>{children}</Card.StaticRoot>;
|
|
36
|
-
}
|
|
37
|
-
};
|