-
Notifications
You must be signed in to change notification settings - Fork 68
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
9f34af0
commit e44193e
Showing
5 changed files
with
99 additions
and
70 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,64 @@ | ||
import { forwardRef } from 'react' | ||
import { forwardRef, HTMLAttributes } from 'react' | ||
import styled, { css } from 'styled-components' | ||
import { group as tokens } from './Group.tokens' | ||
|
||
const { border } = tokens | ||
|
||
const GroupBase = styled.div(() => { | ||
const radius = border.type === 'border' && border.radius | ||
export type GroupProps = { | ||
/** Display Group in vertical direction. */ | ||
vertical?: boolean | ||
} & HTMLAttributes<HTMLDivElement> | ||
|
||
return css` | ||
> * { | ||
border-radius: 0; | ||
@media (hover: hover) and (pointer: fine) { | ||
&:hover { | ||
border-radius: 0; | ||
} | ||
const radius = border.type === 'border' && border.radius | ||
|
||
const GroupBase = styled.div<GroupProps>` | ||
> * { | ||
border-radius: 0; | ||
@media (hover: hover) and (pointer: fine) { | ||
&:hover { | ||
border-radius: 0; | ||
} | ||
} | ||
> :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 type GroupProps = React.HTMLAttributes<HTMLDivElement> | ||
} | ||
${({ vertical }) => | ||
vertical | ||
? css` | ||
display: grid; | ||
> :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 Group = forwardRef<HTMLDivElement, GroupProps>(function Group( | ||
{ children, ...rest }, | ||
{ children, vertical, ...rest }, | ||
ref, | ||
) { | ||
return ( | ||
<GroupBase ref={ref} {...rest}> | ||
{children} | ||
</GroupBase> | ||
) | ||
const props = { | ||
ref, | ||
vertical, | ||
...rest, | ||
} | ||
return <GroupBase {...props}>{children}</GroupBase> | ||
}) |