Skip to content

Commit

Permalink
Add Box component (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhabib authored Jun 6, 2024
1 parent e2bd356 commit 7176790
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 148 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@vanilla-extract/webpack-plugin": "^2.3.6",
"babel-loader": "^9.1.0",
"classnames": "^2.3.2",
"clsx": "^2.1.1",
"codemirror": "^5.65.10",
"command-line-args": "^5.2.1",
"command-line-usage": "^6.1.3",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions src/Playroom/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import clsx, { type ClassValue } from 'clsx';
import type { AllHTMLAttributes, ElementType } from 'react';
import { sprinkles, type Sprinkles } from '../sprinkles.css';

interface BoxProps
extends Omit<
AllHTMLAttributes<HTMLElement>,
'width' | 'height' | 'className' | 'data'
>,
Sprinkles {
className?: ClassValue;
component?: ElementType;
}

export const Box = ({
component = 'div',
className,
...restProps
}: BoxProps) => {
const atomProps: Record<string, unknown> = {};

for (const key in restProps) {
if (sprinkles.properties.has(key as keyof Sprinkles)) {
atomProps[key] = restProps[key as keyof typeof restProps];
delete restProps[key as keyof typeof restProps];
}
}

const classes = clsx(className, sprinkles({ ...atomProps }));
const Component = component;

return <Component className={classes} {...restProps} />;
};
3 changes: 2 additions & 1 deletion src/Playroom/Button/Button.css.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { style, createVar } from '@vanilla-extract/css';
import { calc } from '@vanilla-extract/css-utils';
import { sprinkles, vars, colorPaletteVars } from '../sprinkles.css';
import { sprinkles, colorPaletteVars } from '../sprinkles.css';
import { vars } from '../vars.css';

export const reset = style([
sprinkles({
Expand Down
3 changes: 2 additions & 1 deletion src/Playroom/CodeEditor/CodeEditor.css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { style, globalStyle, keyframes, createVar } from '@vanilla-extract/css';
import { vars, colorPaletteVars, sprinkles } from '../sprinkles.css';
import { colorPaletteVars, sprinkles } from '../sprinkles.css';
import { vars } from '../vars.css';
import { toolbarItemSize } from '../ToolbarItem/ToolbarItem.css';

const minimumLineNumberWidth = '50px';
Expand Down
57 changes: 21 additions & 36 deletions src/Playroom/Frames/Frames.css.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
import { style } from '@vanilla-extract/css';
import { sprinkles } from '../sprinkles.css';

export const root = style([
sprinkles({
height: 'full',
boxSizing: 'border-box',
display: 'flex',
padding: 'gutter',
textAlign: 'center',
overflow: 'auto',
}),
]);

export const framesContainer = style([
sprinkles({
display: 'flex',
gap: 'gutter',
}),
{
marginInline: 'auto',
},
]);
export const root = sprinkles({
height: 'full',
boxSizing: 'border-box',
display: 'flex',
padding: 'gutter',
textAlign: 'center',
overflow: 'auto',
});

export const frameContainer = style([
sprinkles({
position: 'relative',
height: 'full',
textAlign: 'left',
display: 'flex',
flexDirection: 'column',
}),
{},
]);
export const frameContainer = sprinkles({
position: 'relative',
height: 'full',
textAlign: 'left',
display: 'flex',
flexDirection: 'column',
});

export const frame = style([
sprinkles({ position: 'relative', height: 'full', border: 0 }),
{
flexGrow: 1,
},
]);
export const frame = sprinkles({
position: 'relative',
height: 'full',
border: 0,
flexGrow: 1,
});

export const frameBorder = style([
sprinkles({
Expand Down
5 changes: 3 additions & 2 deletions src/Playroom/Frames/Frames.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import playroomConfig from '../../config';
import frameSrc from './frameSrc';

import * as styles from './Frames.css';
import { Box } from '../Box/Box';

interface FramesProps {
code: string;
Expand All @@ -34,7 +35,7 @@ export default function Frames({ code, themes, widths }: FramesProps) {

return (
<div ref={scrollingPanelRef} className={styles.root}>
<div className={styles.framesContainer}>
<Box display="flex" gap="gutter" marginX="auto">
{frames.map((frame) => (
<div
key={`${frame.theme}_${frame.width}`}
Expand Down Expand Up @@ -65,7 +66,7 @@ export default function Frames({ code, themes, widths }: FramesProps) {
</div>
</div>
))}
</div>
</Box>
</div>
);
}
7 changes: 2 additions & 5 deletions src/Playroom/FramesPanel/FramesPanel.css.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { calc } from '@vanilla-extract/css-utils';
import { globalStyle, style } from '@vanilla-extract/css';
import { colorPaletteVars, sprinkles, vars } from '../sprinkles.css';

export const title = style({
marginRight: 'auto',
});
import { colorPaletteVars, sprinkles } from '../sprinkles.css';
import { vars } from '../vars.css';

export const reset = style([
sprinkles({
Expand Down
9 changes: 5 additions & 4 deletions src/Playroom/FramesPanel/FramesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { ToolbarPanel } from '../ToolbarPanel/ToolbarPanel';
import { StoreContext } from '../../StoreContext/StoreContext';
import { Stack } from '../Stack/Stack';
import { Text } from '../Text/Text';

import * as styles from './FramesPanel.css';
import { Helmet } from 'react-helmet';
import { Inline } from '../Inline/Inline';
import { Box } from '../Box/Box';

import * as styles from './FramesPanel.css';

const getTitle = (title: string | undefined) => {
if (title) {
Expand Down Expand Up @@ -47,9 +48,9 @@ interface FrameHeadingProps {
}
const FrameHeading = ({ showReset, onReset, children }: FrameHeadingProps) => (
<Inline space="none" alignY="center">
<div className={styles.title}>
<Box flexGrow={1}>
<Heading level="3">{children}</Heading>
</div>
</Box>
{showReset && <ResetButton onClick={onReset}>Clear</ResetButton>}
</Inline>
);
Expand Down
3 changes: 2 additions & 1 deletion src/Playroom/Heading/Heading.css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sprinkles, vars, colorPaletteVars } from '../sprinkles.css';
import { sprinkles, colorPaletteVars } from '../sprinkles.css';
import { vars } from '../vars.css';
import { style } from '@vanilla-extract/css';

export const base = style([
Expand Down
2 changes: 1 addition & 1 deletion src/Playroom/Inline/Inline.css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { style, createVar, styleVariants } from '@vanilla-extract/css';
import { vars } from '../sprinkles.css';
import { vars } from '../vars.css';

const size = createVar();
const horizontalAlignment = createVar();
Expand Down
3 changes: 2 additions & 1 deletion src/Playroom/Playroom.css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { style, globalStyle } from '@vanilla-extract/css';
import { sprinkles, vars, colorPaletteVars } from './sprinkles.css';
import { sprinkles, colorPaletteVars } from './sprinkles.css';
import { vars } from './vars.css';
import { toolbarItemSize } from './ToolbarItem/ToolbarItem.css';

globalStyle('html', {
Expand Down
11 changes: 2 additions & 9 deletions src/Playroom/SettingsPanel/SettingsPanel.css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { colorPaletteVars, sprinkles, vars } from '../sprinkles.css';
import { colorPaletteVars, sprinkles } from '../sprinkles.css';
import { vars } from '../vars.css';
import { style } from '@vanilla-extract/css';

export const fieldset = sprinkles({
Expand All @@ -7,14 +8,6 @@ export const fieldset = sprinkles({
padding: 'none',
});

export const keyboardShortcutsRow = sprinkles({
alignItems: 'center',
});

export const keyboardShortcutTitle = style({
marginRight: 'auto',
});

export const keyboardShortcutKeys = style([
{
display: 'grid',
Expand Down
5 changes: 3 additions & 2 deletions src/Playroom/SettingsPanel/SettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ColorModeDarkIcon from '../icons/ColorModeDarkIcon';
import { Text } from '../Text/Text';
import { Inline } from '../Inline/Inline';
import { isMac } from '../../utils/formatting';
import { Box } from '../Box/Box';

const getKeyBindings = () => {
const metaKeySymbol = isMac() ? '⌘' : 'Ctrl';
Expand Down Expand Up @@ -72,9 +73,9 @@ const KeyboardShortcut = ({

return (
<Inline space="small" alignY="center">
<div className={styles.keyboardShortcutTitle}>
<Box flexGrow={1}>
<Text>{description}</Text>
</div>
</Box>
<Text size={isMac() ? 'large' : 'standard'}>
<div className={styles.keyboardShortcutKeys}>{shortcutSegments}</div>
</Text>
Expand Down
3 changes: 2 additions & 1 deletion src/Playroom/Snippets/SearchField/SearchField.css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sprinkles, vars, colorPaletteVars } from '../../sprinkles.css';
import { sprinkles, colorPaletteVars } from '../../sprinkles.css';
import { vars } from '../../vars.css';
import { style } from '@vanilla-extract/css';

export const field = style([
Expand Down
3 changes: 2 additions & 1 deletion src/Playroom/Snippets/Snippets.css.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { style } from '@vanilla-extract/css';
import { toolbarItemSize } from '../ToolbarItem/ToolbarItem.css';
import { sprinkles, vars, colorPaletteVars } from '../sprinkles.css';
import { sprinkles, colorPaletteVars } from '../sprinkles.css';
import { vars } from '../vars.css';

export const root = sprinkles({
position: 'relative',
Expand Down
2 changes: 1 addition & 1 deletion src/Playroom/Stack/Stack.css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { style, createVar, styleVariants } from '@vanilla-extract/css';
import { vars } from '../sprinkles.css';
import { vars } from '../vars.css';

const size = createVar();

Expand Down
3 changes: 2 additions & 1 deletion src/Playroom/StatusMessage/StatusMessage.css.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { calc } from '@vanilla-extract/css-utils';
import { style } from '@vanilla-extract/css';
import { sprinkles, vars, colorPaletteVars } from '../sprinkles.css';
import { sprinkles, colorPaletteVars } from '../sprinkles.css';
import { vars } from '../vars.css';
import { toolbarItemSize } from '../ToolbarItem/ToolbarItem.css';

const statusGutter = '15px';
Expand Down
28 changes: 0 additions & 28 deletions src/Playroom/Toolbar/Toolbar.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,6 @@ export const sidebar = sprinkles({
overflow: 'hidden',
});

export const topButtons = sprinkles({
transition: 'medium',
});

export const positions_isOpen = style({});
export const positionContainer = style([
sprinkles({
position: 'absolute',
top: 0,
width: 'full',
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-end',
justifyContent: 'flex-end',
transition: 'medium',
}),
{
bottom: toolbarItemSize,
selectors: {
[`&:not(${positions_isOpen})`]: {
opacity: 0,
pointerEvents: 'none',
transform: 'translateY(20px)',
},
},
},
]);

export const buttons = style([
sprinkles({
display: 'flex',
Expand Down
2 changes: 1 addition & 1 deletion src/Playroom/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
)}
<div className={styles.sidebar}>
<div className={styles.buttons}>
<div className={styles.topButtons}>
<div>
{hasSnippets && (
<ToolbarItem
active={isSnippetsOpen}
Expand Down
3 changes: 2 additions & 1 deletion src/Playroom/ToolbarItem/ToolbarItem.css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sprinkles, vars, colorPaletteVars } from '../sprinkles.css';
import { sprinkles, colorPaletteVars } from '../sprinkles.css';
import { vars } from '../vars.css';
import { style, globalStyle } from '@vanilla-extract/css';

export const toolbarItemSize = 60;
Expand Down
2 changes: 1 addition & 1 deletion src/Playroom/icons/ChevronIcon.css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { style } from '@vanilla-extract/css';
import { vars } from '../sprinkles.css';
import { vars } from '../vars.css';

export const root = style({
transition: vars.transition.medium,
Expand Down
Loading

0 comments on commit 7176790

Please sign in to comment.