Skip to content

Commit

Permalink
feat(box): support className
Browse files Browse the repository at this point in the history
  • Loading branch information
Niznikr committed Oct 4, 2024
1 parent a0b138f commit a889052
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-falcons-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@launchpad-ui/box": patch
---

Support `className` for `Box`
1 change: 1 addition & 0 deletions packages/box/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@launchpad-ui/vars": "workspace:~",
"@radix-ui/react-slot": "1.1.0",
"@vanilla-extract/dynamic": "2.1.0",
"class-variance-authority": "0.7.0",
"rainbow-sprinkles": "0.17.3"
},
"peerDependencies": {
Expand Down
18 changes: 6 additions & 12 deletions packages/box/src/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import type { ReactNode } from 'react';
import type { HTMLAttributes } from 'react';
import type { Sprinkles } from './styles/rainbow-sprinkles.css';

import { Slot } from '@radix-ui/react-slot';
import { cx } from 'class-variance-authority';

import { rainbowSprinkles } from './styles/rainbow-sprinkles.css';

type BoxProps = Sprinkles & {
children?: ReactNode;
interface BoxProps extends Sprinkles, Omit<HTMLAttributes<HTMLDivElement>, 'color'> {
asChild?: boolean;
'data-test-id'?: string;
};
}

const Box = ({
asChild,
children,
'data-test-id': testId = asChild ? undefined : 'box',
...props
}: BoxProps) => {
const Box = ({ asChild, children, className: classes, ...props }: BoxProps) => {
const Component = asChild ? Slot : 'div';
const { className, style, otherProps } = rainbowSprinkles(props);

return (
<Component className={className} style={style} data-test-id={testId} {...otherProps}>
<Component className={cx(classes, className)} style={style} {...otherProps}>
{children}
</Component>
);
Expand Down
12 changes: 12 additions & 0 deletions packages/box/src/styles/rainbow-sprinkles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const responsiveProperties = defineProperties({
paddingRight: vars.spacing,
paddingTop: vars.spacing,
paddingBottom: vars.spacing,
paddingBlock: vars.spacing,
paddingBlockEnd: vars.spacing,
paddingBlockStart: vars.spacing,
paddingInline: vars.spacing,
paddingInlineEnd: vars.spacing,
paddingInlineStart: vars.spacing,
top: vars.spacing,
left: vars.spacing,
right: vars.spacing,
Expand All @@ -55,6 +61,12 @@ const responsiveProperties = defineProperties({
marginLeft: vars.spacing,
marginRight: vars.spacing,
marginBottom: vars.spacing,
marginBlock: vars.spacing,
marginBlockEnd: vars.spacing,
marginBlockStart: vars.spacing,
marginInline: vars.spacing,
marginInlineEnd: vars.spacing,
marginInlineStart: vars.spacing,
borderRadius: vars.borderRadius,
borderWidth: vars.borderWidth,
font: typographies,
Expand Down
2 changes: 1 addition & 1 deletion packages/box/stories/Box.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StoryObj } from '@storybook/react';

import { Button } from '@launchpad-ui/button';
import { Button } from '@launchpad-ui/components';

import { Box } from '../src';

Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit a889052

Please sign in to comment.