-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlignGroup.stories.tsx
More file actions
72 lines (61 loc) · 1.91 KB
/
AlignGroup.stories.tsx
File metadata and controls
72 lines (61 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import type { Meta } from '@storybook/react-vite';
import { useEffect, useState } from 'react';
import type { AlignGroupProps } from '../../src/index.js';
import { AlignGroup, useBBoxObserver } from '../../src/index.js';
const DEBUG_COLOR = 'yellow';
export default {
title: 'Components/AlignGroup',
component: AlignGroup,
} as Meta;
const lorem = 'lorem ipsum';
export function Control(props: Omit<AlignGroupProps, 'children'>) {
return (
<div>
<svg style={{ overflow: 'visible' }} width={200} height={200}>
<line x1={100} x2={100} y1={0} y2={200} stroke={DEBUG_COLOR} />
<line x1={0} x2={200} y1={100} y2={100} stroke={DEBUG_COLOR} />
<AlignGroup {...props}>
<rect fill="red" width={10} height={10} />
<text>lorem</text>
</AlignGroup>
</svg>
</div>
);
}
Control.args = {
x: 100,
y: 100,
verticalAlign: 'start',
horizontalAlign: 'start',
style: { fontSize: '20px' },
};
function VariableText() {
const [text, setText] = useState(lorem);
useEffect(() => {
const interval = setInterval(
() => setText(lorem.slice(Math.round(Math.random() * lorem.length))),
500,
);
return () => clearInterval(interval);
}, []);
return <text fill="white">{text}</text>;
}
export function VariableSize() {
const { ref, ...size } = useBBoxObserver();
return (
<div>
<svg style={{ overflow: 'visible' }} width={200} height={200}>
<line x1={100} x2={100} y1={0} y2={200} stroke={DEBUG_COLOR} />
<line x1={0} x2={200} y1={100} y2={100} stroke={DEBUG_COLOR} />
<AlignGroup x={100} y={100} horizontalAlign="end" verticalAlign="end">
<rect fill="green" {...size} />
<g ref={ref}>
<rect fill="red" width={10} height={10} />
<VariableText />
</g>
</AlignGroup>
</svg>
</div>
);
}
VariableSize.storyName = 'Variable size is repositioned';