Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
add specific type
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Jan 4, 2022
1 parent e9d7c30 commit 517f80a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
1 change: 1 addition & 0 deletions assets/js/atomic/blocks/product-elements/title/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const Block = ( props: Props ): JSX.Element => {
? {
...spacingProps.style,
...typographyProps.style,
...colorProps.style,
}
: {}
}
Expand Down
11 changes: 5 additions & 6 deletions assets/js/atomic/blocks/product-elements/title/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 15 additions & 17 deletions assets/js/utils/style-attributes-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) || {};
Expand Down Expand Up @@ -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 : {};

Expand All @@ -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 )
Expand All @@ -88,18 +88,16 @@ 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: '',
style: {},
};
}

return __experimentalUseColorProps( attributes );
const attributesObject = isObject( attributes ) ? attributes : {};
const style = parseStyle( attributesObject.style );

return __experimentalUseColorProps( { ...attributesObject, style } );
};

0 comments on commit 517f80a

Please sign in to comment.