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 5e477db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
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
27 changes: 11 additions & 16 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,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: '',
Expand Down

0 comments on commit 5e477db

Please sign in to comment.