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: add variant options with new colors #2121

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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/shiny-crews-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kadena/react-ui": minor
---

Added a new variant to apply different colors to the Divider component
44 changes: 32 additions & 12 deletions packages/libs/react-ui/src/components/Divider/Divider.css.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
import { token } from '../../styles';
import { atoms } from '../../styles/atoms.css';
import { tokens } from '../../styles/index';

export const dividerClass = style([
atoms({
width: '100%',
marginBlock: 'lg',
border: 'none',
}),
{
backgroundColor: tokens.kda.foundation.color.border.base.bold,
height: tokens.kda.foundation.border.width.hairline,
export const dividerClass = recipe({
base: [
atoms({
width: '100%',
marginBlock: 'lg',
border: 'none',
}),
{
height: token('border.width.hairline'),
},
],
variants: {
variant: {
subtle: {
backgroundColor: token('color.border.base.subtle'),
},
base: {
backgroundColor: token('color.border.base.default'),
},
bold: {
backgroundColor: token('color.border.base.bold'),
},
boldest: {
backgroundColor: token('color.border.base.boldest'),
},
highContrast: {
backgroundColor: token('color.border.base.high-contrast'),
},
},
},
]);
});
18 changes: 15 additions & 3 deletions packages/libs/react-ui/src/components/Divider/Divider.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';
import { withContentWidth } from '../../storyDecorators';
import { getVariants } from '../../storyDecorators/getVariants';
import { Card } from '../Card';
import { Divider } from './Divider';
import { dividerClass } from './Divider.css';

const variants = getVariants(dividerClass);

const meta: Meta = {
title: 'Layout/Divider',
decorators: [withContentWidth],
argTypes: {
variant: {
control: {
type: 'select',
},
options: variants.variant,
},
},
parameters: {
status: { type: 'releaseCandidate' },
status: { type: 'stable' },
docs: {
description: {
component:
Expand All @@ -24,7 +36,7 @@ type Story = StoryObj;
export const Static: Story = {
name: 'Divider',

render: () => {
render: (args) => {
return (
<>
<Card>
Expand All @@ -35,7 +47,7 @@ export const Static: Story = {
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
<Divider />
<Divider {...args} />
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
Expand Down
21 changes: 18 additions & 3 deletions packages/libs/react-ui/src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import type { RecipeVariants } from '@vanilla-extract/recipes';
import cn from 'classnames';
import type { ComponentPropsWithRef, FC } from 'react';
import React from 'react';
import { useSeparator } from 'react-aria';
import { dividerClass } from './Divider.css';

export interface IDividerProps extends ComponentPropsWithRef<'hr'> {}
type Variants = NonNullable<RecipeVariants<typeof dividerClass>>;

export const Divider: FC<IDividerProps> = ({ className, ...props }) => {
export interface IDividerProps extends ComponentPropsWithRef<'hr'> {
variant?: Variants['variant'];
}

export const Divider: FC<IDividerProps> = ({
className,
variant = 'base',
...props
}) => {
const { separatorProps } = useSeparator({
...props,
elementType: 'hr',
orientation: 'horizontal',
});
return <hr className={cn(dividerClass, className)} {...separatorProps} />;

return (
<hr
className={cn(dividerClass({ variant }), className)}
{...separatorProps}
/>
);
};