@a-type/ui 0.8.27 → 0.8.29
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/cjs/components/horizontalList/HorizontalList.d.ts +10 -0
- package/dist/cjs/components/horizontalList/HorizontalList.js +78 -0
- package/dist/cjs/components/horizontalList/HorizontalList.js.map +1 -0
- package/dist/cjs/components/horizontalList/HorizontalList.stories.d.ts +18 -0
- package/dist/cjs/components/horizontalList/HorizontalList.stories.js +28 -0
- package/dist/cjs/components/horizontalList/HorizontalList.stories.js.map +1 -0
- package/dist/cjs/components/horizontalList.d.ts +1 -0
- package/dist/cjs/components/horizontalList.js +19 -0
- package/dist/cjs/components/horizontalList.js.map +1 -0
- package/dist/cjs/components/scrollArea/ScrollArea.d.ts +21 -0
- package/dist/cjs/components/scrollArea/ScrollArea.js +69 -0
- package/dist/cjs/components/scrollArea/ScrollArea.js.map +1 -0
- package/dist/cjs/components/scrollArea.d.ts +1 -0
- package/dist/cjs/components/scrollArea.js +19 -0
- package/dist/cjs/components/scrollArea.js.map +1 -0
- package/dist/css/main.css +2 -2
- package/dist/esm/components/horizontalList/HorizontalList.d.ts +10 -0
- package/dist/esm/components/horizontalList/HorizontalList.js +71 -0
- package/dist/esm/components/horizontalList/HorizontalList.js.map +1 -0
- package/dist/esm/components/horizontalList/HorizontalList.stories.d.ts +18 -0
- package/dist/esm/components/horizontalList/HorizontalList.stories.js +25 -0
- package/dist/esm/components/horizontalList/HorizontalList.stories.js.map +1 -0
- package/dist/esm/components/horizontalList.d.ts +1 -0
- package/dist/esm/components/horizontalList.js +3 -0
- package/dist/esm/components/horizontalList.js.map +1 -0
- package/dist/esm/components/scrollArea/ScrollArea.d.ts +21 -0
- package/dist/esm/components/scrollArea/ScrollArea.js +43 -0
- package/dist/esm/components/scrollArea/ScrollArea.js.map +1 -0
- package/dist/esm/components/scrollArea.d.ts +1 -0
- package/dist/esm/components/scrollArea.js +3 -0
- package/dist/esm/components/scrollArea.js.map +1 -0
- package/package.json +2 -1
- package/src/components/horizontalList/HorizontalList.stories.tsx +79 -0
- package/src/components/horizontalList/HorizontalList.tsx +110 -0
- package/src/components/horizontalList.ts +1 -0
- package/src/components/scrollArea/ScrollArea.tsx +87 -0
- package/src/components/scrollArea.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollArea.js","sourceRoot":"","sources":["../../../src/components/scrollArea.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a-type/ui",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"/dist",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"@radix-ui/react-menu": "^2.0.6",
|
|
58
58
|
"@radix-ui/react-popover": "^1.0.7",
|
|
59
59
|
"@radix-ui/react-radio-group": "^1.1.3",
|
|
60
|
+
"@radix-ui/react-scroll-area": "^1.1.0",
|
|
60
61
|
"@radix-ui/react-select": "^2.0.0",
|
|
61
62
|
"@radix-ui/react-slider": "^1.1.2",
|
|
62
63
|
"@radix-ui/react-slot": "^1.0.2",
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { HorizontalList } from './HorizontalList.js';
|
|
3
|
+
import { Button } from '../button.js';
|
|
4
|
+
import { Icon } from '../icon.js';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'HorizontalList',
|
|
9
|
+
component: HorizontalList,
|
|
10
|
+
argTypes: {},
|
|
11
|
+
args: {
|
|
12
|
+
children: (
|
|
13
|
+
<>
|
|
14
|
+
<Button size="small">One</Button>
|
|
15
|
+
<Button size="small">Two</Button>
|
|
16
|
+
<Button size="small">Three</Button>
|
|
17
|
+
<Button size="small">Four but long</Button>
|
|
18
|
+
<Button size="small">Five</Button>
|
|
19
|
+
<Button size="small">Six</Button>
|
|
20
|
+
<Button size="small">Seven</Button>
|
|
21
|
+
<Button size="small">Eight</Button>
|
|
22
|
+
<Button size="small">Nine</Button>
|
|
23
|
+
<Button size="small">Ten</Button>
|
|
24
|
+
<Button size="small">Eleven</Button>
|
|
25
|
+
<Button size="small">Twelve</Button>
|
|
26
|
+
<Button size="small">Thirteen</Button>
|
|
27
|
+
<Button size="small">Fourteen and long</Button>
|
|
28
|
+
<Button size="small">Fifteen</Button>
|
|
29
|
+
<Button size="small">Sixteen</Button>
|
|
30
|
+
<Button size="small">Seventeen</Button>
|
|
31
|
+
<Button size="small">Eighteen</Button>
|
|
32
|
+
<Button size="small">Nineteen</Button>
|
|
33
|
+
<Button size="small">Twenty</Button>
|
|
34
|
+
<Button size="small">Twenty one</Button>
|
|
35
|
+
<Button size="small">Twenty two</Button>
|
|
36
|
+
<Button size="small">Twenty three</Button>
|
|
37
|
+
<Button size="small">Twenty four</Button>
|
|
38
|
+
<Button
|
|
39
|
+
size="icon"
|
|
40
|
+
color="primary"
|
|
41
|
+
className="sticky right-2 bottom-2 flex-shrink-0 shadow-sm ml-auto"
|
|
42
|
+
>
|
|
43
|
+
<Icon name="plus" />
|
|
44
|
+
</Button>
|
|
45
|
+
</>
|
|
46
|
+
),
|
|
47
|
+
},
|
|
48
|
+
parameters: {
|
|
49
|
+
controls: { expanded: true },
|
|
50
|
+
},
|
|
51
|
+
} satisfies Meta<typeof HorizontalList>;
|
|
52
|
+
|
|
53
|
+
export default meta;
|
|
54
|
+
|
|
55
|
+
type Story = StoryObj<typeof HorizontalList>;
|
|
56
|
+
|
|
57
|
+
export const Default: Story = {
|
|
58
|
+
render: (args) => {
|
|
59
|
+
const [open, setOpen] = useState(false);
|
|
60
|
+
return (
|
|
61
|
+
<div className="bg-black flex flex-col items-center h-full">
|
|
62
|
+
<div className="bg-white w-400px flex flex-col items-stretch h-full">
|
|
63
|
+
<Button
|
|
64
|
+
toggled={open}
|
|
65
|
+
onClick={() => setOpen(!open)}
|
|
66
|
+
className="mt-auto mb-1 mr-1 self-end"
|
|
67
|
+
>
|
|
68
|
+
{open ? 'Close' : 'Open'}
|
|
69
|
+
</Button>
|
|
70
|
+
<HorizontalList
|
|
71
|
+
className="border-t border-t-solid border-t-black max-h-200px"
|
|
72
|
+
open={open}
|
|
73
|
+
{...args}
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import { ReactNode, useEffect, useRef } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
ScrollAreaProps,
|
|
5
|
+
ScrollAreaRoot,
|
|
6
|
+
ScrollAreaScrollbar,
|
|
7
|
+
ScrollAreaViewport,
|
|
8
|
+
} from '../scrollArea/ScrollArea.js';
|
|
9
|
+
|
|
10
|
+
export interface HorizontalListProps {
|
|
11
|
+
open?: boolean;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
className?: string;
|
|
14
|
+
contentClassName?: string;
|
|
15
|
+
background?: ScrollAreaProps['background'];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function HorizontalList({
|
|
19
|
+
open,
|
|
20
|
+
children,
|
|
21
|
+
className,
|
|
22
|
+
contentClassName,
|
|
23
|
+
background,
|
|
24
|
+
...rest
|
|
25
|
+
}: HorizontalListProps) {
|
|
26
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
28
|
+
const rememberedWidth = useRef<number>(0);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const content = contentRef.current;
|
|
32
|
+
const container = containerRef.current;
|
|
33
|
+
if (!content || !container) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const contentWidth = content.offsetWidth;
|
|
37
|
+
const containerHeight = container.offsetHeight;
|
|
38
|
+
if (open) {
|
|
39
|
+
// measure content width and animate to container width
|
|
40
|
+
const containerWidth = container.offsetWidth;
|
|
41
|
+
rememberedWidth.current = contentWidth;
|
|
42
|
+
content.style.setProperty('width', `${containerWidth}px`);
|
|
43
|
+
content.style.setProperty('flex-wrap', 'wrap');
|
|
44
|
+
// force measure to get the new height
|
|
45
|
+
const contentHeight = content.offsetHeight;
|
|
46
|
+
console.log({ containerHeight, contentHeight });
|
|
47
|
+
container
|
|
48
|
+
.animate(
|
|
49
|
+
[
|
|
50
|
+
{ height: `${containerHeight}px` },
|
|
51
|
+
{ height: `${contentHeight}px` },
|
|
52
|
+
],
|
|
53
|
+
{
|
|
54
|
+
easing: 'cubic-bezier(0.64, -0.25, 0.1, 1.4)',
|
|
55
|
+
duration: 200,
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
.finished.then(() => {});
|
|
59
|
+
} else {
|
|
60
|
+
content.style.setProperty('width', `auto`);
|
|
61
|
+
content.style.setProperty('flex-wrap', 'nowrap');
|
|
62
|
+
// force measure to get new height
|
|
63
|
+
const contentHeight = content.offsetHeight;
|
|
64
|
+
container
|
|
65
|
+
.animate(
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
height: `${containerHeight}px`,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
height: `${contentHeight}px`,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
{
|
|
75
|
+
easing: 'cubic-bezier(0.64, -0.25, 0.1, 1.4)',
|
|
76
|
+
duration: 200,
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
.finished.then(() => {});
|
|
80
|
+
}
|
|
81
|
+
}, [open, contentRef, containerRef]);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<ScrollAreaRoot
|
|
85
|
+
className={clsx(
|
|
86
|
+
'flex flex-col',
|
|
87
|
+
'layer-components:max-h-300px',
|
|
88
|
+
className,
|
|
89
|
+
)}
|
|
90
|
+
background={background}
|
|
91
|
+
data-state={open ? 'open' : 'closed'}
|
|
92
|
+
{...rest}
|
|
93
|
+
>
|
|
94
|
+
<ScrollAreaViewport ref={containerRef}>
|
|
95
|
+
<div
|
|
96
|
+
className={clsx(
|
|
97
|
+
'layer-components:(px-3 pt-3 pb-4 gap-2)',
|
|
98
|
+
'flex flex-row gap-2 flex-shrink-0 w-max-content w-auto)',
|
|
99
|
+
contentClassName,
|
|
100
|
+
)}
|
|
101
|
+
ref={contentRef}
|
|
102
|
+
>
|
|
103
|
+
{children}
|
|
104
|
+
</div>
|
|
105
|
+
</ScrollAreaViewport>
|
|
106
|
+
<ScrollAreaScrollbar />
|
|
107
|
+
<ScrollAreaScrollbar orientation="horizontal" />
|
|
108
|
+
</ScrollAreaRoot>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './horizontalList/HorizontalList.js';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as Primitive from '@radix-ui/react-scroll-area';
|
|
2
|
+
import { withClassName } from '../../hooks.js';
|
|
3
|
+
import { forwardRef, useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
const ScrollAreaRootImpl = withClassName(
|
|
6
|
+
Primitive.Root,
|
|
7
|
+
'overflow-hidden bg-[var(--bg)]',
|
|
8
|
+
'layer-components:([--bg:var(--color-wash)] [--shadow:var(--color-shadow-1))])',
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export interface ScrollAreaRootProps extends Primitive.ScrollAreaProps {
|
|
12
|
+
background?: 'white' | 'wash' | 'primary-wash' | 'primary' | 'black';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ScrollAreaRoot = forwardRef<any, ScrollAreaRootProps>(
|
|
16
|
+
function ScrollAreaRoot({ background = 'wash', ...props }, ref) {
|
|
17
|
+
const bgStyle: any = useMemo(
|
|
18
|
+
() => ({
|
|
19
|
+
'--bg': `var(--color-${background})`,
|
|
20
|
+
'--shadow': `var(--color-${shadowMap[background]})`,
|
|
21
|
+
}),
|
|
22
|
+
[background],
|
|
23
|
+
);
|
|
24
|
+
return <ScrollAreaRootImpl ref={ref} style={bgStyle} {...props} />;
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const ScrollAreaViewport = withClassName(
|
|
29
|
+
Primitive.Viewport,
|
|
30
|
+
'h-full w-full',
|
|
31
|
+
'[background:linear-gradient(var(--bg)_30%,rgba(255,255,255,0))_center_top,linear-gradient(rgba(255,255,255,0),var(--bg)_70%)_center_bottom,radial-gradient(farthest-side_at_50%_0,var(--shadow),rgba(0,0,0,0))_center_top,radial-gradient(farthest-side_at_50%_100%,var(--shadow),rgba(0,0,0,0))_center_bottom]',
|
|
32
|
+
'![background-repeat:no-repeat] ![background-size:100%_40px,100%_40px,100%_14px,100%_14px]',
|
|
33
|
+
'![background-attachment:local,local,scroll,scroll]',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const ScrollAreaScrollbarRoot = withClassName(
|
|
37
|
+
Primitive.Scrollbar,
|
|
38
|
+
'layer-components:(flex select-none touch-none p-0.5 bg-gray-2 transition-colors duration-160ms ease-out)',
|
|
39
|
+
'layer-components:hover:bg-gray-3',
|
|
40
|
+
'layer-components:[&[data-orientation=vertical]]:w-2.5',
|
|
41
|
+
'layer-components:[&[data-orientation=horizontal]]:(flex-col h-2.5)',
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const ScrollAreaThumb = withClassName(
|
|
45
|
+
Primitive.Thumb,
|
|
46
|
+
'layer-components:(flex-1 rounded-lg relative bg-gray-5)',
|
|
47
|
+
'before:(content-[""] absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full min-w-44px min-h-44px)',
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const ScrollAreaScrollbar = forwardRef<
|
|
51
|
+
any,
|
|
52
|
+
Primitive.ScrollAreaScrollbarProps
|
|
53
|
+
>(function ScrollAreaScrollbar(props, ref) {
|
|
54
|
+
return (
|
|
55
|
+
<ScrollAreaScrollbarRoot {...props} ref={ref}>
|
|
56
|
+
<ScrollAreaThumb />
|
|
57
|
+
</ScrollAreaScrollbarRoot>
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export interface ScrollAreaProps extends Primitive.ScrollAreaProps {
|
|
62
|
+
background?: ScrollAreaRootProps['background'];
|
|
63
|
+
orientation?: 'vertical' | 'both';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const ScrollArea = forwardRef<any, ScrollAreaProps>(function ScrollArea(
|
|
67
|
+
{ children, orientation, ...props },
|
|
68
|
+
ref,
|
|
69
|
+
) {
|
|
70
|
+
return (
|
|
71
|
+
<ScrollAreaRoot ref={ref} {...props}>
|
|
72
|
+
<ScrollAreaViewport>{children}</ScrollAreaViewport>
|
|
73
|
+
<ScrollAreaScrollbar />
|
|
74
|
+
{orientation === 'both' && (
|
|
75
|
+
<ScrollAreaScrollbar orientation="horizontal" />
|
|
76
|
+
)}
|
|
77
|
+
</ScrollAreaRoot>
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const shadowMap = {
|
|
82
|
+
white: 'shadow-1',
|
|
83
|
+
wash: 'shadow-1',
|
|
84
|
+
'primary-wash': 'shadow-2',
|
|
85
|
+
primary: 'shadow-1',
|
|
86
|
+
black: 'overlay',
|
|
87
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './scrollArea/ScrollArea.js';
|