1
1
import { transparentize } from '@theme-ui/color'
2
2
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
+ }
3
8
/**
4
9
* Mixin to generate consistent box-shadow rule for focus rings and selections
5
10
*/
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 = { } ) => {
10
12
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 ) ) } `
12
14
}
13
15
}
14
16
@@ -23,17 +25,18 @@ export const focusBoxShadow = color => (t = {}) => {
23
25
* }
24
26
* `
25
27
*/
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
27
30
if ( disabled ) {
28
31
return {
29
32
outline : 'none'
30
33
}
31
34
}
32
35
return {
33
36
outline : 'none' ,
34
- borderColor : transparentize ( color , 0 ) ( theme ) , // This serves as a getter from theme
37
+ borderColor : themeColor ,
35
38
transition : 'box-shadow .25s' ,
36
- ...focusBoxShadow ( color ) ( theme )
39
+ ...focusBoxShadow ( themeColor ) ( theme )
37
40
}
38
41
}
39
42
@@ -46,17 +49,18 @@ export const focusRingStyles = (color, disabled = false) => (theme = {}) => {
46
49
* ${focusRing('red')}
47
50
* `
48
51
*/
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 ) )
50
54
const baseStyles = {
51
55
'.js-focus-visible &:focus:not(.focus-visible)' : {
52
56
outline : 0
53
57
} ,
54
- '&.focus-visible' : focusRingStyles ( color , disabled ) ( theme )
58
+ '&.focus-visible' : styles
55
59
}
56
60
if ( hover ) {
57
61
return {
58
62
...baseStyles ,
59
- '&:hover:not(:disabled)' : focusRingStyles ( color , disabled ) ( theme )
63
+ '&:hover:not(:disabled)' : styles
60
64
}
61
65
}
62
66
return baseStyles
0 commit comments