Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(box): support className #1432

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I find this a little confusing and would prefer to rename the sprinkles variable to make it more obvious what's happening, but that's minor and you can take or leave that suggestion.

</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.

Loading