Skip to content

Commit

Permalink
Inlining focus ring behavior into components
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Apr 11, 2024
1 parent 55094ff commit dbdf86a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 66 deletions.
28 changes: 21 additions & 7 deletions src/components/Button/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@ const outlineStyle = {
} as const

export const buttonVariants = recipe({
base: atoms({
overflow: 'hidden',
whiteSpace: 'nowrap',
alignItems: 'center',
border: 'none',
textDecoration: 'none',
}),
base: [
atoms({
overflow: 'hidden',
whiteSpace: 'nowrap',
alignItems: 'center',
border: 'none',
textDecoration: 'none',
}),
{
selectors: {
'&:focus': {
outline: 'none',
},

'&:focus-visible': {
outline: 'none',
boxShadow: `0 0 0 ${vars.borderWidths.thick} ${vars.colors.borderFocus} inset`,
},
},
},
],

variants: {
variant: {
Expand Down
53 changes: 34 additions & 19 deletions src/components/Checkbox/styles.css.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import { RecipeVariants, recipe } from '@vanilla-extract/recipes'

import { atoms } from '~/css'
import { atoms, vars } from '~/css'

export const checkboxVariants = recipe({
base: atoms({
borderRadius: 'xs',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
borderWidth: 'thin',
borderStyle: 'solid',
borderColor: 'borderFocus',
background: 'transparent',
opacity: {
base: '100',
hover: '80',
disabled: '50',
},
cursor: {
base: 'pointer',
disabled: 'default',
base: [
atoms({
borderRadius: 'xs',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
borderWidth: 'thin',
borderStyle: 'solid',
borderColor: 'borderFocus',
background: 'transparent',
opacity: {
base: '100',
hover: '80',
disabled: '50',
},
cursor: {
base: 'pointer',
disabled: 'default',
},
}),
{
selectors: {
'&:focus': {
outline: 'none',
},

'&:focus-visible': {
outline: 'none',
boxShadow: `0 0 0 ${vars.borderWidths.thick} ${vars.colors.borderFocus} inset`,
borderColor: 'transparent',
},
},
},
}),
],

variants: {
size: {
Expand Down
9 changes: 9 additions & 0 deletions src/components/Form/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ControlledSelect as Select } from '~/components/Select'
import { ControlledSwitch as Switch } from '~/components/Switch'
import { Text } from '~/components/Text'
import { ControlledTextInput as TextInput } from '~/components/TextInput'

Check warning on line 11 in src/components/Form/Form.stories.tsx

View workflow job for this annotation

GitHub Actions / Test

There should be at least one empty line between import groups

Check warning on line 11 in src/components/Form/Form.stories.tsx

View workflow job for this annotation

GitHub Actions / build-and-deploy

There should be at least one empty line between import groups
import { TextArea } from '../TextArea'

import { Form } from './Form'
export default {
Expand Down Expand Up @@ -96,6 +97,14 @@ export const Default: Story = {
<Text color="negative">{errors.fileInput.message as string}</Text>
)}

<TextArea
defaultValue=""
label="Message"
labelLocation="top"
name="message"
placeholder="Enter a message"
/>

<Select
control={control}
defaultValue={selectOptions[0].value}
Expand Down
45 changes: 30 additions & 15 deletions src/components/RadioGroup/styles.css.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
import { style } from '@vanilla-extract/css'
import { RecipeVariants, recipe } from '@vanilla-extract/recipes'

import { atoms } from '~/css'
import { atoms, vars } from '~/css'

export const radioItemVariants = recipe({
base: atoms({
background: 'transparent',
borderRadius: 'circle',
borderStyle: 'solid',
borderColor: 'borderFocus',
padding: '0',
cursor: {
base: 'pointer',
disabled: 'default',
},
opacity: {
hover: '80',
disabled: '50',
base: [
atoms({
background: 'transparent',
borderRadius: 'circle',
borderStyle: 'solid',
borderColor: 'borderFocus',
padding: '0',
cursor: {
base: 'pointer',
disabled: 'default',
},
opacity: {
hover: '80',
disabled: '50',
},
}),
{
selectors: {
'&:focus': {
outline: 'none',
},

'&:focus-visible': {
outline: 'none',
boxShadow: `0 0 0 ${vars.borderWidths.thick} ${vars.colors.borderFocus} inset`,
borderColor: 'transparent',
},
},
},
}),
],

variants: {
size: {
Expand Down
10 changes: 5 additions & 5 deletions src/components/Select/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export const triggerStyle = style([
opacity: 0.5,
},

'&:focus': {
outline: 'none',
},

'&:focus-within': {
outline: 'none',
opacity: '1 !important',
// outlineColor: vars.colors.borderFocus,
// outlineStyle: 'solid',
// outlineOffset: `calc(${vars.borderWidths.thick} * -1)`,
// outlineWidth: vars.borderWidths.thick,

boxShadow: `0 0 0 ${vars.borderWidths.thick} ${vars.colors.borderFocus} inset`,
borderColor: 'transparent',
},
Expand Down
9 changes: 9 additions & 0 deletions src/components/Switch/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export const root = style([
cursor: 'default',
opacity: '0.5',
},

'&:focus': {
outline: 'none',
},

'&:focus-visible': {
outline: 'none',
boxShadow: `0 0 0 ${vars.borderWidths.thick} ${vars.colors.borderFocus} inset`,
},
},
},
])
Expand Down
20 changes: 0 additions & 20 deletions src/css/global.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,13 @@ globalStyle('*', {
fontVariant: 'unset',
fontWeight: 'unset',
margin: 0,
outline: 'unset',
padding: 0,
})

globalStyle('*, *::before, *::after', {
boxSizing: 'border-box',
})

globalStyle('*:focus', {
outline: 'none',
})

globalStyle('*:focus-visible', {
// outlineColor: `${vars.colors.borderFocus} !important`,
// outlineStyle: 'solid',
// outlineOffset: `calc(${vars.borderWidths.thick} * -1)`,
// outlineWidth: vars.borderWidths.thick,

outline: 'none',

// Safari does not apply a border radius to outlines so we will use a boxShadow instead to acheive that same inset effect
boxShadow: `0 0 0 ${vars.borderWidths.thick} ${vars.colors.borderFocus} inset`,

// Because we use a semi transparent focus ring we want to set any border color to transparent so it doesnt show through
borderColor: 'transparent',
})

globalStyle('body', {
fontSize: '1rem',
})
Expand Down

0 comments on commit dbdf86a

Please sign in to comment.