Skip to content

Commit

Permalink
refactor(form-builder): move focus ring utils/hoc to components
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Apr 26, 2021
1 parent 57a61aa commit 796e5f0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './withFocusRing'
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import styled, {css} from 'styled-components'
import {rem, Theme} from '@sanity/ui'
import {ComponentType} from 'react'
import {focusRingBorderStyle, focusRingStyle} from './helpers'

export function withFocusRing<Props>(component: ComponentType<Props>) {
return styled(component)(({theme}: {theme: Theme}) => {
const border = {width: 1, color: 'var(--card-border-color)'}

return css`
--card-focus-box-shadow: ${focusRingBorderStyle(border)};
border-radius: ${rem(theme.sanity.radius[1])};
outline: none;
box-shadow: var(--card-focus-box-shadow);
&:focus {
--card-focus-box-shadow: ${focusRingStyle({
base: theme.sanity.color.base,
border,
focusRing: theme.sanity.focusRing,
})};
}
`
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
UploaderResolver,
UploadOptions,
} from '../../../sanity/uploads/types'
import ImageToolInput from '../ImageToolInput'
import {ImageToolInput} from '../ImageToolInput'
import PatchEvent, {set, setIfMissing, unset} from '../../../PatchEvent'
import UploadPlaceholder from '../common/UploadPlaceholder'
import WithMaterializedReference from '../../../utils/WithMaterializedReference'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import React from 'react'
import {useId} from '@reach/auto-id'
import styled, {css} from 'styled-components'
import {Button, Theme} from '@sanity/ui'

import {focusRingBorderStyle, focusRingStyle} from '../focusringUtils'
import {focusRingBorderStyle, focusRingStyle} from '../../../../components/withFocusRing/helpers'

type Props = Omit<React.ComponentProps<typeof Button>, 'type' | 'value' | 'onSelect'> & {
accept?: string
Expand Down
26 changes: 4 additions & 22 deletions packages/@sanity/form-builder/src/inputs/files/common/styles.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
/* eslint-disable import/named */

import styled, {css, DefaultTheme, StyledComponent} from 'styled-components'
import {Card, rem, Theme} from '@sanity/ui'
import styled, {DefaultTheme, StyledComponent} from 'styled-components'
import {Card} from '@sanity/ui'
import {fileTarget} from '../../common/fileTarget'
import {focusRingBorderStyle, focusRingStyle} from './focusringUtils'
import {withFocusRing} from '../../../components/withFocusRing'

export type {FileInfo} from '../../common/fileTarget'

export const FileTarget = styled(fileTarget(Card))(({theme}: {theme: Theme}) => {
const border = {width: 1, color: 'var(--card-border-color)'}

return css`
--card-focus-box-shadow: ${focusRingBorderStyle(border)};
border-radius: ${rem(theme.sanity.radius[1])};
outline: none;
box-shadow: var(--card-focus-box-shadow);
&:focus {
--card-focus-box-shadow: ${focusRingStyle({
base: theme.sanity.color.base,
border,
focusRing: theme.sanity.focusRing,
})};
}
`
})
export const FileTarget = withFocusRing(fileTarget(Card))

export const Overlay: StyledComponent<'div', DefaultTheme> = styled.div`
position: absolute;
Expand Down

0 comments on commit 796e5f0

Please sign in to comment.