-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59e0dec
commit a538934
Showing
5 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@kadena/kode-ui': minor | ||
--- | ||
|
||
add buttongroup component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/libs/kode-ui/src/components/ButtonGroup/ButtonGroup.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { globalStyle, recipe, style, token } from './../../../styles'; | ||
|
||
export const buttonGroupClass = style({}); | ||
|
||
export const buttonGroupRecipe = recipe({ | ||
base: {}, | ||
variants: { | ||
variant: { | ||
primary: {}, | ||
transparent: {}, | ||
info: {}, | ||
warning: {}, | ||
positive: {}, | ||
negative: {}, | ||
outlined: {}, | ||
}, | ||
}, | ||
}); | ||
|
||
globalStyle( | ||
`${buttonGroupClass} button:not(:first-child):not(:last-child), ${buttonGroupClass} a:not(:first-child):not(:last-child)`, | ||
{ | ||
borderRadius: 0, | ||
}, | ||
); | ||
|
||
globalStyle( | ||
`${buttonGroupClass} button:first-child, ${buttonGroupClass} a:first-child`, | ||
{ | ||
borderEndEndRadius: 0, | ||
borderStartEndRadius: 0, | ||
}, | ||
); | ||
globalStyle( | ||
`${buttonGroupClass} button:last-child, ${buttonGroupClass} a:last-child`, | ||
{ | ||
borderEndStartRadius: 0, | ||
borderStartStartRadius: 0, | ||
}, | ||
); | ||
|
||
//variants | ||
globalStyle( | ||
`${buttonGroupClass}[data-variant="primary"] button:not(:first-child), ${buttonGroupClass}[data-variant="primary"] a:not(:first-child)`, | ||
{ | ||
border: 0, | ||
borderInlineStartWidth: '1px', | ||
borderStyle: 'solid', | ||
borderColor: 'yellow', | ||
}, | ||
); | ||
|
||
globalStyle( | ||
`${buttonGroupClass} button:not(:last-child), ${buttonGroupClass} a:not(:last-child)`, | ||
{ | ||
borderInlineEndWidth: '0', | ||
}, | ||
); |
77 changes: 77 additions & 0 deletions
77
packages/libs/kode-ui/src/components/ButtonGroup/ButtonGroup.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { MonoChevronLeft, MonoChevronRight } from '@kadena/kode-icons'; | ||
import type { Meta, StoryFn, StoryObj } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { Avatar, Badge, Button, Link, Stack } from '..'; | ||
import { getVariants } from '../../storyDecorators/getVariants'; | ||
import { Box } from '../Layout/Box/Box'; | ||
import type { IButtonGroupProps } from './ButtonGroup'; | ||
import { ButtonGroup } from './ButtonGroup'; | ||
import { buttonGroupRecipe } from './ButtonGroup.css'; | ||
|
||
const variants = getVariants(buttonGroupRecipe); | ||
|
||
const meta: Meta<IButtonGroupProps> = { | ||
title: 'Components/ButtonGroup', | ||
parameters: { | ||
controls: { | ||
hideNoControlsWarning: true, | ||
sort: 'requiredFirst', | ||
}, | ||
docs: { | ||
description: { | ||
component: | ||
'The ButtonGroup is a component that will group a set of buttons (some small style changes on the buttons). ', | ||
}, | ||
}, | ||
}, | ||
argTypes: { | ||
onPress: { | ||
action: 'clicked', | ||
description: 'callback when button is clicked', | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
variant: { | ||
options: variants.variant, | ||
control: { | ||
type: 'select', | ||
}, | ||
description: 'button style variant', | ||
}, | ||
isCompact: { | ||
description: 'compact button style', | ||
control: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
type ButtonGroupStory = StoryObj<IButtonGroupProps>; | ||
|
||
export const Primary: ButtonGroupStory = { | ||
args: { | ||
variant: 'primary', | ||
onPress: () => undefined, | ||
}, | ||
render: (props: IButtonGroupProps) => { | ||
return ( | ||
<Stack gap="lg" flexDirection="column"> | ||
<ButtonGroup {...props}> | ||
<Button>option1</Button> | ||
<Button>option2</Button> | ||
<Button endVisual={<MonoChevronLeft />} /> | ||
</ButtonGroup> | ||
<ButtonGroup {...props}> | ||
<Link>option1</Link> | ||
<Link>option2</Link> | ||
<Link endVisual={<MonoChevronLeft />} /> | ||
</ButtonGroup> | ||
</Stack> | ||
); | ||
}, | ||
}; | ||
|
||
export default meta; |
39 changes: 39 additions & 0 deletions
39
packages/libs/kode-ui/src/components/ButtonGroup/ButtonGroup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import classNames from 'classnames'; | ||
import type { FC, PropsWithChildren } from 'react'; | ||
import React from 'react'; | ||
import type { IButtonProps } from '../Button/Button'; | ||
import { Stack } from '../Layout'; | ||
import { buttonGroupClass, buttonGroupRecipe } from './ButtonGroup.css'; | ||
|
||
interface IBUttonGroupProps extends PropsWithChildren { | ||
variant: IButtonProps['variant']; | ||
isCompact: IButtonProps['isCompact']; | ||
} | ||
|
||
export const ButtonGroup: FC<IBUttonGroupProps> = ({ | ||
children, | ||
variant, | ||
isCompact, | ||
}) => { | ||
return ( | ||
<Stack | ||
as="section" | ||
data-variant={variant} | ||
className={classNames( | ||
buttonGroupClass, | ||
buttonGroupRecipe({ | ||
variant, | ||
}), | ||
)} | ||
> | ||
{React.Children.map(children, (child) => { | ||
if (!React.isValidElement(child)) return null; | ||
return React.cloneElement(child, { | ||
...child.props, | ||
variant, | ||
isCompact, | ||
}); | ||
})} | ||
</Stack> | ||
); | ||
}; |