-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Add ButtonGroup to Storybook (#2420)
* π Update Usage * π Add ButtonGroup * βοΈ Fix typo * π Add Introduction * β¨ Add vertical prop & story * π§ Add SplitButton * β¨ Add role to Group * π Fix menu btn position * π Update group style * βΏοΈ Add aria-label & a11y description * βΏοΈ Update a11y description * π Update component name from Group to ButtonGroup * π Change display * π Update display to flex-inline * π¨ Move ButtonGroup under Button * βΏοΈ Add aria-label * βοΈ Fix typo
- Loading branch information
1 parent
6aa0d28
commit edb4de3
Showing
8 changed files
with
257 additions
and
85 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
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
File renamed without changes.
68 changes: 68 additions & 0 deletions
68
packages/eds-core-react/src/components/Button/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,68 @@ | ||
import { forwardRef, HTMLAttributes } from 'react' | ||
import styled, { css } from 'styled-components' | ||
import { group as tokens } from './ButtonGroup.tokens' | ||
|
||
const { border } = tokens | ||
|
||
export type ButtonGroupProps = { | ||
/** Display ButtonGroup vertically. */ | ||
vertical?: boolean | ||
} & HTMLAttributes<HTMLDivElement> | ||
|
||
const radius = border.type === 'border' && border.radius | ||
|
||
const ButtonGroupBase = styled.div<ButtonGroupProps>` | ||
display: inline-flex; | ||
> * { | ||
border-radius: 0; | ||
@media (hover: hover) and (pointer: fine) { | ||
&:hover { | ||
border-radius: 0; | ||
} | ||
} | ||
} | ||
${({ vertical }) => | ||
vertical | ||
? css` | ||
flex-direction: column; | ||
> :first-child { | ||
border-top-left-radius: ${radius}; | ||
border-top-right-radius: ${radius}; | ||
} | ||
> :last-child { | ||
border-bottom-left-radius: ${radius}; | ||
border-bottom-right-radius: ${radius}; | ||
} | ||
> :not(:last-child) { | ||
border-bottom: none; | ||
} | ||
` | ||
: css` | ||
> :first-child { | ||
border-top-left-radius: ${radius}; | ||
border-bottom-left-radius: ${radius}; | ||
} | ||
> :last-child { | ||
border-top-right-radius: ${radius}; | ||
border-bottom-right-radius: ${radius}; | ||
} | ||
> :not(:last-child) { | ||
border-right: none; | ||
} | ||
`} | ||
` | ||
|
||
export const ButtonGroup = forwardRef<HTMLDivElement, ButtonGroupProps>( | ||
function ButtonGroup({ children, vertical, ...rest }, ref) { | ||
const props = { | ||
ref, | ||
vertical, | ||
...rest, | ||
} | ||
return ( | ||
<ButtonGroupBase role="group" {...props}> | ||
{children} | ||
</ButtonGroupBase> | ||
) | ||
}, | ||
) |
1 change: 1 addition & 0 deletions
1
packages/eds-core-react/src/components/Button/ButtonGroup/index.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 @@ | ||
export * from './ButtonGroup' |
Oops, something went wrong.