generated from tchryssos/next-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from tchryssos/tc-sotww-updates
Sotww updates
- Loading branch information
Showing
24 changed files
with
378 additions
and
203 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 was deleted.
Oops, something went wrong.
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,88 @@ | ||
import styled from '@emotion/styled'; | ||
import { | ||
autoUpdate, | ||
flip, | ||
offset, | ||
shift, | ||
useDismiss, | ||
useFloating, | ||
useFocus, | ||
useHover, | ||
useInteractions, | ||
useRole, | ||
} from '@floating-ui/react'; | ||
import { PropsWithChildren, useState } from 'react'; | ||
|
||
import { pxToRem } from '~/logic/utils/styles/pxToRem'; | ||
|
||
import { Box } from './box/Box'; | ||
|
||
interface TooltipProps { | ||
id: string; | ||
tipText: string; | ||
isLabeled: boolean; | ||
} | ||
|
||
const Target = styled.div``; | ||
|
||
const Tip = styled.span` | ||
background: ${({ theme }) => theme.colors.background}; | ||
color: ${({ theme }) => theme.colors.text}; | ||
width: ${pxToRem(200)}; | ||
padding: ${({ theme }) => theme.spacing[8]}; | ||
border: 1px solid ${({ theme }) => theme.colors.text}; | ||
`; | ||
|
||
export function Tooltip({ | ||
id, | ||
children, | ||
tipText, | ||
isLabeled, | ||
}: PropsWithChildren<TooltipProps>) { | ||
const [show, setShow] = useState(false); | ||
const { refs, floatingStyles, context } = useFloating({ | ||
open: show, | ||
whileElementsMounted: autoUpdate, | ||
onOpenChange: setShow, | ||
middleware: [offset(10), flip(), shift()], | ||
}); | ||
|
||
const hover = useHover(context, { move: false }); | ||
const focus = useFocus(context); | ||
const dismiss = useDismiss(context); | ||
const role = useRole(context, { | ||
role: isLabeled ? 'tooltip' : 'label', | ||
}); | ||
|
||
// Merge all the interactions into prop getters | ||
const { getReferenceProps, getFloatingProps } = useInteractions([ | ||
hover, | ||
focus, | ||
dismiss, | ||
role, | ||
]); | ||
|
||
return ( | ||
<Box position="relative"> | ||
{show && ( | ||
<Tip | ||
id={id} | ||
ref={refs.setFloating} | ||
role="tooltip" | ||
style={floatingStyles} | ||
{...getFloatingProps()} | ||
> | ||
{tipText} | ||
</Tip> | ||
)} | ||
<Target | ||
aria-describedby={id} | ||
ref={refs.setReference} | ||
tabIndex={0} | ||
{...getReferenceProps()} | ||
> | ||
{children} | ||
</Target> | ||
</Box> | ||
); | ||
} |
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,37 @@ | ||
import { pxToRem } from '~/logic/utils/styles/pxToRem'; | ||
|
||
import { Box } from '../box/Box'; | ||
import { DividerWrapper, Label, Segment } from './components'; | ||
import { DividerProps } from './types'; | ||
|
||
export function Divider({ | ||
color = 'text', | ||
vertical, | ||
className, | ||
label, | ||
}: DividerProps) { | ||
if (vertical) { | ||
return ( | ||
<Box | ||
backgroundColor={color} | ||
className={className} | ||
height="100%" | ||
width={pxToRem(1)} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<DividerWrapper center className={className}> | ||
{label && ( | ||
<> | ||
<Segment color={color} /> | ||
<Label as="p" variant="body"> | ||
{label} | ||
</Label> | ||
</> | ||
)} | ||
<Segment color={color} /> | ||
</DividerWrapper> | ||
); | ||
} |
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,20 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import { FlexBox } from '../box/FlexBox'; | ||
import { Text } from '../Text'; | ||
import { DividerProps } from './types'; | ||
|
||
export const DividerWrapper = styled(FlexBox)` | ||
min-height: ${({ theme }) => theme.borderWidth[1]}; | ||
width: 100%; | ||
`; | ||
|
||
export const Segment = styled.div<Pick<DividerProps, 'color'>>` | ||
width: 100%; | ||
height: ${({ theme }) => theme.borderWidth[1]}; | ||
background-color: ${({ theme, color }) => theme.colors[color || 'text']}; | ||
`; | ||
|
||
export const Label = styled(Text)` | ||
padding: 0 ${({ theme }) => theme.spacing[16]}; | ||
`; |
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,16 @@ | ||
import { Color } from '~/typings/theme'; | ||
|
||
type HorizDividerProps = { | ||
label?: string; | ||
vertical?: never | false; | ||
}; | ||
|
||
type VerticalDividerProps = { | ||
label?: never; | ||
vertical: true; | ||
}; | ||
|
||
export type DividerProps = { | ||
color?: Color; | ||
className?: string; | ||
} & (HorizDividerProps | VerticalDividerProps); |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.