From f8dd4fdd91aa9dcc028276955429c0a51764de3c Mon Sep 17 00:00:00 2001 From: yoshi6jp Date: Wed, 29 Nov 2023 05:19:14 +0900 Subject: [PATCH] fix(Divider): support v4 (#434) --- src/Divider/Divider.stories.tsx | 109 +++++++++++++++++++++++++++++++- src/Divider/Divider.tsx | 81 ++++++++++++++++-------- 2 files changed, 161 insertions(+), 29 deletions(-) diff --git a/src/Divider/Divider.stories.tsx b/src/Divider/Divider.stories.tsx index d47b8d28..d4c6214d 100644 --- a/src/Divider/Divider.stories.tsx +++ b/src/Divider/Divider.stories.tsx @@ -4,13 +4,14 @@ import { StoryFn as Story, Meta } from '@storybook/react' import Divider, { DividerProps } from '.' import Card from '../Card' -export default { +const meta: Meta = { title: 'Layout/Divider', component: Divider, args: { children: 'OR', }, -} as Meta +} +export default meta export const Default: Story = ({ children, ...args }) => { return ( @@ -77,3 +78,107 @@ export const Responsive: Story = ({ children, ...args }) => { Responsive.args = { responsive: true, } + +export const Colors: Story = ({ children, color, ...args }) => { + return ( +
+ Default + + Neutral + + + Primary + + + Secondary + + + Accent + + + Success + + + Warning + + + Info + + + Error + +
+ ) +} +Colors.argTypes = { + children: { + control: false, + }, + color: { + control: false, + }, +} + +export const DifferentPositions: Story = ({ + children, + start, + end, + ...args +}) => { + return ( +
+ + Start + + Default + + End + +
+ ) +} +DifferentPositions.argTypes = { + children: { + control: false, + }, + start: { + control: false, + }, + end: { + control: false, + }, +} + +export const DifferentPositionsHorizontal: Story = ({ + children, + start, + end, + ...args +}) => { + return ( +
+ + Start + + Default + + End + +
+ ) +} +DifferentPositionsHorizontal.argTypes = { + children: { + control: false, + }, + start: { + control: false, + }, + end: { + control: false, + }, +} + +DifferentPositionsHorizontal.args = { + horizontal: true, +} diff --git a/src/Divider/Divider.tsx b/src/Divider/Divider.tsx index 5fd2063a..017f1f7f 100644 --- a/src/Divider/Divider.tsx +++ b/src/Divider/Divider.tsx @@ -1,40 +1,67 @@ -import React from 'react' +import React, { forwardRef } from 'react' import clsx from 'clsx' import { twMerge } from 'tailwind-merge' -import { IComponentBaseProps } from '../types' +import { IComponentBaseProps, ComponentColor } from '../types' -export type DividerProps = React.HTMLAttributes & +export type DividerProps = Omit, 'color'> & IComponentBaseProps & { vertical?: boolean horizontal?: boolean responsive?: boolean + start?: boolean + end?: boolean + color?: Exclude } -const Divider = ({ - children, - vertical, - horizontal, - responsive, - dataTheme, - className, - ...props -}: DividerProps): JSX.Element => { - const classes = twMerge( - 'divider', - className, - clsx({ - 'divider-vertical': vertical, - 'divider-horizontal': horizontal, - 'lg:divider-horizontal': responsive, - }) - ) +const Divider = forwardRef( + ( + { + children, + vertical, + horizontal, + responsive, + color, + start, + end, + dataTheme, + className, + ...props + }, + ref + ): JSX.Element => { + const classes = twMerge( + 'divider', + className, + clsx({ + 'divider-vertical': vertical, + 'divider-horizontal': horizontal, + 'lg:divider-horizontal': responsive, + 'divider-neutral': color === 'neutral', + 'divider-primary': color === 'primary', + 'divider-secondary': color === 'secondary', + 'divider-accent': color === 'accent', + 'divider-warning': color === 'warning', + 'divider-info': color === 'info', + 'divider-error': color === 'error', + 'divider-start': start, + 'divider-end': end, + }) + ) - return ( -
- {children} -
- ) -} + return ( +
+ {children} +
+ ) + } +) +Divider.displayName = 'Divider' export default Divider