-
Notifications
You must be signed in to change notification settings - Fork 161
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
6324560
commit 971f07a
Showing
14 changed files
with
72 additions
and
61 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,6 @@ | ||
--- | ||
"@rocket.chat/onboarding-ui": minor | ||
"@rocket.chat/fuselage": minor | ||
--- | ||
|
||
feat(fuselage): Avoid `Box` usage on `ButtonGroup` |
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
83 changes: 46 additions & 37 deletions
83
packages/fuselage/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 |
---|---|---|
@@ -1,48 +1,57 @@ | ||
import type { ComponentProps } from 'react'; | ||
import React from 'react'; | ||
import type { HTMLAttributes, Ref } from 'react'; | ||
import React, { forwardRef } from 'react'; | ||
|
||
import { appendClassName } from '../../helpers/appendClassName'; | ||
import { patchChildren } from '../../helpers/patchChildren'; | ||
import Box from '../Box'; | ||
|
||
type ButtonGroupProps = Omit<ComponentProps<typeof Box>, 'wrap'> & { | ||
type ButtonGroupProps = { | ||
align?: 'start' | 'center' | 'end'; | ||
stretch?: boolean; | ||
wrap?: boolean; | ||
vertical?: boolean; | ||
small?: boolean; | ||
large?: boolean; | ||
}; | ||
} & HTMLAttributes<HTMLDivElement>; | ||
|
||
export const ButtonGroup = ({ | ||
align = 'start', | ||
children, | ||
stretch, | ||
vertical, | ||
wrap, | ||
small, | ||
large, | ||
...props | ||
}: ButtonGroupProps) => ( | ||
<Box | ||
rcx-button-group | ||
rcx-button-group--align={align} | ||
rcx-button-group--stretch={stretch} | ||
rcx-button-group--vertical={vertical} | ||
rcx-button-group--small={small} | ||
rcx-button-group--large={large} | ||
rcx-button-group--wrap={wrap} | ||
role='group' | ||
{...props} | ||
> | ||
{patchChildren( | ||
children, | ||
(childProps: { className: string | string[] }) => ({ | ||
className: appendClassName( | ||
childProps.className, | ||
'rcx-button-group__item' | ||
), | ||
}) | ||
)} | ||
</Box> | ||
); | ||
export const ButtonGroup = forwardRef(function ButtonGroup( | ||
{ | ||
align = 'start', | ||
children, | ||
stretch, | ||
vertical, | ||
wrap, | ||
small, | ||
large, | ||
...props | ||
}: ButtonGroupProps, | ||
ref: Ref<HTMLDivElement> | ||
) { | ||
return ( | ||
<div | ||
ref={ref} | ||
className={[ | ||
'rcx-button-group', | ||
stretch && 'rcx-button-group--stretch', | ||
vertical && 'rcx-button-group--vertical', | ||
align && `rcx-button-group--align-${align}`, | ||
small && 'rcx-button-group--small', | ||
large && 'rcx-button-group--large', | ||
wrap && 'rcx-button-group--wrap', | ||
] | ||
.filter(Boolean) | ||
.join(' ')} | ||
role='group' | ||
{...props} | ||
> | ||
{patchChildren( | ||
children, | ||
(childProps: { className: string | string[] }) => ({ | ||
className: appendClassName( | ||
childProps.className, | ||
'rcx-button-group__item' | ||
), | ||
}) | ||
)} | ||
</div> | ||
); | ||
}); |
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
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
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
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
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
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