11import { transparentize } from '@theme-ui/color'
22
3+ // Check if it's a props object or the theme
4+ // theme-ui provides theme as an argument where styled-system uses props.theme
5+ function getTheme ( theme = { } ) {
6+ return theme [ 'theme' ] || theme
7+ }
38/**
49 * Mixin to generate consistent box-shadow rule for focus rings and selections
510 */
6- export const focusBoxShadow = color => ( t = { } ) => {
7- // Check if it's a props object or the theme
8- // theme-ui provides theme as an argument where styled-system uses props.theme
9- let theme = t . theme || t
11+ export const focusBoxShadow = color => ( theme = { } ) => {
1012 return {
11- boxShadow : `0 0 0 0.2em ${ transparentize ( color , 0.75 ) ( theme ) } `
13+ boxShadow : `0 0 0 0.2em ${ transparentize ( color , 0.75 ) ( getTheme ( theme ) ) } `
1214 }
1315}
1416
@@ -23,17 +25,18 @@ export const focusBoxShadow = color => (t = {}) => {
2325 * }
2426 * `
2527 */
26- export const focusRingStyles = ( color , disabled = false ) => ( theme = { } ) => {
28+ export const focusRingStyles = ( color , disabled = false ) => theme => {
29+ const themeColor = transparentize ( color , 0 ) ( getTheme ( theme ) ) // This serves as a getter from theme
2730 if ( disabled ) {
2831 return {
2932 outline : 'none'
3033 }
3134 }
3235 return {
3336 outline : 'none' ,
34- borderColor : transparentize ( color , 0 ) ( theme ) , // This serves as a getter from theme
37+ borderColor : themeColor ,
3538 transition : 'box-shadow .25s' ,
36- ...focusBoxShadow ( color ) ( theme )
39+ ...focusBoxShadow ( themeColor ) ( theme )
3740 }
3841}
3942
@@ -46,17 +49,18 @@ export const focusRingStyles = (color, disabled = false) => (theme = {}) => {
4649 * ${focusRing('red')}
4750 * `
4851 */
49- export const focusRing = ( color , disabled = false , hover = false ) => ( theme = { } ) => {
52+ export const focusRing = ( color , disabled = false , hover = false ) => theme => {
53+ const styles = focusRingStyles ( color , disabled ) ( getTheme ( theme ) )
5054 const baseStyles = {
5155 '.js-focus-visible &:focus:not(.focus-visible)' : {
5256 outline : 0
5357 } ,
54- '&.focus-visible' : focusRingStyles ( color , disabled ) ( theme )
58+ '&.focus-visible' : styles
5559 }
5660 if ( hover ) {
5761 return {
5862 ...baseStyles ,
59- '&:hover:not(:disabled)' : focusRingStyles ( color , disabled ) ( theme )
63+ '&:hover:not(:disabled)' : styles
6064 }
6165 }
6266 return baseStyles
0 commit comments