From 5e477dbe5b3c32fc4c815dd4c42868cb4113af2a Mon Sep 17 00:00:00 2001 From: Luigi Date: Tue, 4 Jan 2022 14:57:23 +0100 Subject: [PATCH] add specific type --- .../blocks/product-elements/title/index.ts | 11 ++++---- assets/js/utils/style-attributes-utils.ts | 27 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/assets/js/atomic/blocks/product-elements/title/index.ts b/assets/js/atomic/blocks/product-elements/title/index.ts index 9ee1af8b9e2..03935b1a702 100644 --- a/assets/js/atomic/blocks/product-elements/title/index.ts +++ b/assets/js/atomic/blocks/product-elements/title/index.ts @@ -28,12 +28,11 @@ const blockConfig: BlockConfiguration = { typography: { fontSize: true, lineHeight: true, - ...( isFeaturePluginBuild() & - { - __experimentalFontWeight: true, - __experimentalTextTransform: true, - __experimentalFontFamily: true, - } ), + ...( isFeaturePluginBuild() && { + __experimentalFontWeight: true, + __experimentalTextTransform: true, + __experimentalFontFamily: true, + } ), }, color: { text: false, diff --git a/assets/js/utils/style-attributes-utils.ts b/assets/js/utils/style-attributes-utils.ts index 15ca869a3ef..5968d4a1f30 100644 --- a/assets/js/utils/style-attributes-utils.ts +++ b/assets/js/utils/style-attributes-utils.ts @@ -10,6 +10,14 @@ import { __experimentalUseColorProps } from '@wordpress/block-editor'; import { isFeaturePluginBuild } from '../settings/blocks/feature-flags'; import { isString, isObject } from '../types/type-guards'; +type WithClass = { + className: string; +}; + +type WithStyle = { + style: Record< string, unknown >; +}; + const parseStyle = ( style: unknown ): Record< string, unknown > => { if ( isString( style ) ) { return JSON.parse( style ) || {}; @@ -53,11 +61,7 @@ const parseSpacingStyle = ( }, {} ); }; -export const useSpacingProps = ( - attributes: unknown -): { - style: Record< string, unknown >; -} => { +export const useSpacingProps = ( attributes: unknown ): WithStyle => { const style = isObject( attributes ) ? parseStyle( attributes.style ) : {}; const spacingStyles = isObject( style.spacing ) ? style.spacing : {}; @@ -66,11 +70,7 @@ export const useSpacingProps = ( }; }; -export const useTypographyProps = ( - attributes: unknown -): { - style: Record< string, unknown >; -} => { +export const useTypographyProps = ( attributes: unknown ): WithStyle => { const attributesObject = isObject( attributes ) ? attributes : {}; const style = parseStyle( attributesObject.style ); const typography = isObject( style.typography ) @@ -88,12 +88,7 @@ export const useTypographyProps = ( }; }; -export const useColorProps = ( - attributes: unknown -): { - className: string; - style: Record< string, unknown >; -} => { +export const useColorProps = ( attributes: unknown ): WithStyle & WithClass => { if ( ! isFeaturePluginBuild() ) { return { className: '',