useCssVarPath.js
2 years ago
useJetStyle.js
2 years ago
useJetStyleSupports.js
2 years ago
useStyle.js
2 years ago
useStyle.js
26 lines
| 1 | import useJetStyleSupports from './useJetStyleSupports'; |
| 2 | import resolveStyle from '../helpers/resolveStyle'; |
| 3 | |
| 4 | const { |
| 5 | useBlockAttributes, |
| 6 | } = JetFBHooks; |
| 7 | |
| 8 | function useStyle( cssVar ) { |
| 9 | const [ attributes, setAttributes ] = useBlockAttributes(); |
| 10 | |
| 11 | const jetStyle = useJetStyleSupports(); |
| 12 | const path = jetStyle[ cssVar ] ?? []; |
| 13 | |
| 14 | if ( !path.length ) { |
| 15 | return [ '', () => {} ]; |
| 16 | } |
| 17 | |
| 18 | const [ value, getUpdatedValue ] = resolveStyle( attributes, path ); |
| 19 | |
| 20 | return [ |
| 21 | value, |
| 22 | newValue => setAttributes( { style: getUpdatedValue( newValue ) } ), |
| 23 | ]; |
| 24 | } |
| 25 | |
| 26 | export default useStyle; |