Skip to content

Commit e709cba

Browse files
committed
chore: use createVariants over getClassNameFactory in Viewport components
1 parent a4d14cf commit e709cba

File tree

8 files changed

+50
-57
lines changed

8 files changed

+50
-57
lines changed
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,33 @@
1-
.ViewportControl {
2-
display: flex;
3-
align-items: center;
4-
justify-content: center;
1+
.viewportControl {
52
position: relative;
6-
height: 1.25rem;
3+
height: 20px;
74
overflow: hidden;
85
border-bottom: 1px solid var(--composify-palette-outline);
96
background-color: var(--composify-palette-surface-container-low);
107
}
118

12-
.ViewportControl-ViewportItem {
9+
.viewportItem {
1310
display: flex;
1411
align-items: center;
1512
justify-content: center;
16-
box-sizing: border-box;
1713
position: absolute;
1814
top: 0;
1915
bottom: 0;
16+
padding: 0;
17+
border: none;
2018
border-left: 2px solid var(--composify-palette-outline);
2119
border-right: 2px solid var(--composify-palette-outline);
2220
background-color: var(--composify-palette-surface-container-low);
23-
transition: all 0.1s linear;
21+
transition: all 0.15s linear;
2422
}
2523

26-
.ViewportControl-ViewportItem:first-child {
24+
.viewportItem:first-child {
2725
border: none;
28-
width: auto !important;
2926
left: 0;
3027
right: 0;
3128
}
3229

33-
.ViewportControl-Highlight {
34-
display: flex;
35-
align-items: center;
36-
justify-content: center;
30+
.highlight {
3731
position: relative;
3832
width: 100%;
3933
height: 100%;
@@ -43,12 +37,12 @@
4337
transition: all 0.1s linear;
4438
}
4539

46-
.ViewportControl-ViewportItem:hover .ViewportControl-Highlight {
40+
.viewportItem:hover .highlight {
4741
z-index: 1;
4842
opacity: 0.7;
4943
}
5044

51-
.ViewportControl-Label {
45+
.label {
5246
position: absolute;
5347
opacity: 0;
5448
pointer-events: none;
@@ -57,7 +51,7 @@
5751
color: var(--composify-palette-on-surface);
5852
}
5953

60-
.ViewportControl-ViewportItem:hover .ViewportControl-Label {
54+
.viewportItem:hover .label {
6155
z-index: 2;
6256
opacity: 1;
6357
}

packages/react/src/editor/ViewportControl/ViewportControl.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { type FC, useCallback, useEffect, useRef, useState } from 'react';
2-
import { getClassNameFactory } from '../../utils';
2+
import { HStack } from '../../preset';
3+
import { createVariants } from '../../utils';
34
import styles from './ViewportControl.module.css';
45

5-
const getClassName = getClassNameFactory('ViewportControl', styles);
6+
const variants = createVariants(styles);
67

78
type Props = {
89
viewports: {
@@ -46,21 +47,26 @@ export const ViewportControl: FC<Props> = ({ viewports, selectedWidth, onClick }
4647
}, [autoScale]);
4748

4849
return (
49-
<div ref={containerRef} className={getClassName()}>
50+
<HStack
51+
ref={containerRef}
52+
alignHorizontal="center"
53+
alignVertical="center"
54+
className={variants('viewportControl')}
55+
>
5056
{viewports
5157
.sort((a, b) => b.width - a.width)
5258
.map((viewport) => (
53-
<div
54-
role="button"
59+
<button
60+
type="button"
5561
key={viewport.width}
56-
className={getClassName('ViewportItem')}
62+
className={variants('viewportItem')}
5763
style={{ width: viewport.width * scale }}
5864
onClick={() => onClick(viewport.width)}
5965
>
60-
<div className={getClassName('Highlight')} />
61-
<span className={getClassName('Label')}>{viewport.label}</span>
62-
</div>
66+
<div className={variants('highlight')} />
67+
<span className={variants('label')}>{viewport.label}</span>
68+
</button>
6369
))}
64-
</div>
70+
</HStack>
6571
);
6672
};
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
.ViewportManager {
2-
display: flex;
3-
flex: 1;
4-
flex-direction: column;
1+
.viewportManager {
52
background-color: var(--composify-palette-surface-container);
63
}
74

8-
.ViewportManager-Content {
9-
flex: 1;
10-
display: flex;
11-
justify-content: center;
5+
.content {
126
overflow: hidden;
13-
margin: 2rem 1rem;
7+
margin: 32px 16px;
148
}

packages/react/src/editor/ViewportManager/ViewportManager.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { type FC, type PropsWithChildren, useState } from 'react';
2-
import { getClassNameFactory } from '../../utils';
2+
import { VStack } from '../../preset';
3+
import { createVariants } from '../../utils';
34
import { ViewportControl } from '../ViewportControl';
45
import { ViewportScaler } from '../ViewportScaler';
56
import styles from './ViewportManager.module.css';
67

7-
const getClassName = getClassNameFactory('ViewportManager', styles);
8+
const variants = createVariants(styles);
89

910
type Props = PropsWithChildren<{
1011
viewports?: {
@@ -52,11 +53,11 @@ export const ViewportManager: FC<Props> = ({
5253
const [width, setWidth] = useState(initialViewport.width);
5354

5455
return (
55-
<section className={getClassName()}>
56+
<VStack flex={1} className={variants('viewportManager')}>
5657
<ViewportControl viewports={viewports} selectedWidth={width} onClick={setWidth} />
57-
<div className={getClassName('Content')}>
58+
<VStack flex={1} alignHorizontal="center" className={variants('content')}>
5859
<ViewportScaler width={width}>{children}</ViewportScaler>
59-
</div>
60-
</section>
60+
</VStack>
61+
</VStack>
6162
);
6263
};

packages/react/src/editor/ViewportScaler/ViewportScaler.module.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
*:has(> .ViewportScaler-Container) {
1+
*:has(> .container) {
22
position: relative;
33
}
44

5-
.ViewportScaler-Container {
5+
.container {
66
position: absolute;
77
top: 0;
88
left: 0;
@@ -11,7 +11,7 @@
1111
pointer-events: none;
1212
}
1313

14-
.ViewportScaler-Target {
14+
.target {
1515
position: absolute;
1616
top: 0;
1717
bottom: 0;

packages/react/src/editor/ViewportScaler/ViewportScaler.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { getBox } from 'css-box-model';
22
import { type FC, type PropsWithChildren, useCallback, useEffect, useRef, useState } from 'react';
3-
import { getClassNameFactory } from '../../utils';
3+
import { createVariants } from '../../utils';
44
import styles from './ViewportScaler.module.css';
55

6-
const getClassName = getClassNameFactory('ViewportScaler', styles);
6+
const variants = createVariants(styles);
77

88
type Props = PropsWithChildren<{
99
width: number;
@@ -46,10 +46,10 @@ export const ViewportScaler: FC<Props> = ({ width, children }) => {
4646

4747
return (
4848
<>
49-
<div ref={containerRef} className={getClassName('Container')} />
49+
<div ref={containerRef} className={variants('container')} />
5050
<div
5151
ref={targetRef}
52-
className={getClassName('Target')}
52+
className={variants('target')}
5353
style={{
5454
width,
5555
height,

packages/react/src/preset/HStack/HStack.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { FC, PropsWithChildren } from 'react';
1+
import type { ComponentProps, FC } from 'react';
22
import { createVariants } from '../../utils';
33
import styles from './HStack.module.css';
44

55
const variants = createVariants(styles);
66

7-
type Props = PropsWithChildren<{
8-
className?: string;
7+
type Props = ComponentProps<'div'> & {
98
alignHorizontal?: 'start' | 'end' | 'center' | 'between' | 'around';
109
alignVertical?: 'stretch' | 'start' | 'end' | 'center';
1110
flex?: number;
@@ -15,7 +14,7 @@ type Props = PropsWithChildren<{
1514
margin?: { top: number; right: number; bottom: number; left: number };
1615
gap?: number;
1716
background?: string;
18-
}>;
17+
};
1918

2019
export const HStack: FC<Props> = ({
2120
className,

packages/react/src/preset/VStack/VStack.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { FC, PropsWithChildren } from 'react';
1+
import type { ComponentProps, FC } from 'react';
22
import { createVariants } from '../../utils';
33
import styles from './VStack.module.css';
44

55
const variants = createVariants(styles);
66

7-
type Props = PropsWithChildren<{
8-
className?: string;
7+
type Props = ComponentProps<'div'> & {
98
alignHorizontal?: 'stretch' | 'start' | 'end' | 'center';
109
alignVertical?: 'start' | 'end' | 'center' | 'between' | 'around';
1110
flex?: number;
@@ -15,7 +14,7 @@ type Props = PropsWithChildren<{
1514
padding?: { top: number; right: number; bottom: number; left: number };
1615
margin?: { top: number; right: number; bottom: number; left: number };
1716
background?: string;
18-
}>;
17+
};
1918

2019
export const VStack: FC<Props> = ({
2120
className,

0 commit comments

Comments
 (0)