Skip to content

Commit

Permalink
Merge pull request #50 from ensdomains/eng-369_thorin-updates
Browse files Browse the repository at this point in the history
Update Thorin to fit app v3
  • Loading branch information
storywithoutend authored Jul 27, 2022
2 parents 293bf2b + 9f4b26f commit 6ee3e2a
Show file tree
Hide file tree
Showing 15 changed files with 867 additions and 288 deletions.
34 changes: 32 additions & 2 deletions components/src/components/atoms/Field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Context = React.createContext<State>(undefined)

type NativeFormProps = React.AllHTMLAttributes<HTMLFormElement>
type NativeLabelProps = React.LabelHTMLAttributes<HTMLLabelElement>
type Placement = 'top' | 'bottom'

export type FieldBaseProps = {
/** Description text or react component. */
Expand All @@ -31,6 +32,8 @@ export type FieldBaseProps = {
inline?: boolean
/** A tokens space key value setting the width of the parent element. */
width?: Space
/** Set the placement of the error and description. Does not affect inline mode. */
labelPlacement?: Placement | { error?: Placement; description?: Placement }
}

type Props = FieldBaseProps & {
Expand Down Expand Up @@ -141,6 +144,15 @@ const Error = styled.div<{ $inline?: boolean }>(
`,
)

const getPlacement = (
label: 'error' | 'description',
fallback: Placement,
placement?: Props['labelPlacement'],
): Placement => {
if (typeof placement === 'string') return placement
return placement?.[label] || fallback
}

export const Field = ({
children,
description,
Expand All @@ -152,6 +164,7 @@ export const Field = ({
required,
inline,
width = 'full',
labelPlacement,
...props
}: Props) => {
const ids = useFieldIds({
Expand All @@ -171,6 +184,13 @@ export const Field = ({
else if (children) content = React.cloneElement(children, ids.content)
else content = children

const descriptionPlacement = getPlacement(
'description',
'bottom',
labelPlacement,
)
const errorPlacement = getPlacement('error', 'bottom', labelPlacement)

return inline ? (
<Container $inline={inline} $width={width}>
<ContainerInner>
Expand Down Expand Up @@ -208,13 +228,23 @@ export const Field = ({
) : (
<LabelContent {...{ ...props, ids, label, labelSecondary, required }} />
)}

{description && descriptionPlacement === 'top' && (
<Description {...ids.description}>{description}</Description>
)}

{error && errorPlacement === 'top' && (
<Error aria-live="polite" {...ids.error}>
{error}
</Error>
)}
{content}

{description && (
{description && descriptionPlacement === 'bottom' && (
<Description {...ids.description}>{description}</Description>
)}

{error && (
{error && errorPlacement === 'bottom' && (
<Error aria-live="polite" {...ids.error}>
{error}
</Error>
Expand Down
24 changes: 24 additions & 0 deletions components/src/components/molecules/Backdrop/Backdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,33 @@ export const Backdrop = ({

React.useEffect(() => {
toggle(open || false)

let top = 0
if (typeof window !== 'undefined' && open) {
top = window.scrollY
document.body.style.position = 'fixed'
document.body.style.top = `-${top}px`
}

return () => {
if (typeof window !== 'undefined' && open) {
document.body.style.position = ''
document.body.style.top = ''
window.scroll({
top,
})
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open])

React.useEffect(() => {
return () => {
document.body.style.position = ''
document.body.style.top = ''
}
}, [])

return state !== 'unmounted' ? (
<Portal className={className}>
{onDismiss && (
Expand Down
8 changes: 6 additions & 2 deletions components/src/components/molecules/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,13 @@ const DropdownMenu = ({
}

if (wrapper) {
return wrapper(<MenuButton {...props} />, value || label)
return wrapper(
<MenuButton {...props} type="button" />,
value || label,
)
}

return <MenuButton {...props} key={value || label} />
return <MenuButton {...props} key={value || label} type="button" />
})}
</DropdownMenuContainer>
)
Expand Down Expand Up @@ -512,6 +515,7 @@ export const Dropdown = ({
$direction={direction}
$open={isOpen}
$size={size}
type="button"
onClick={() => setIsOpen(!isOpen)}
>
{label}
Expand Down
Loading

0 comments on commit 6ee3e2a

Please sign in to comment.