2022-08-11 00:04:12 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-02-03 09:54:16 +00:00
|
|
|
import { isObject, isString } from '@woocommerce/types';
|
2023-05-30 13:45:59 +00:00
|
|
|
import type { Style as StyleEngineProperties } from '@wordpress/style-engine/src/types';
|
2022-08-11 00:04:12 +00:00
|
|
|
|
2023-05-30 13:45:59 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import type { StyleProps } from './use-style-props';
|
2022-08-11 00:04:12 +00:00
|
|
|
|
2023-05-12 12:42:16 +00:00
|
|
|
type blockAttributes = {
|
2023-05-30 13:45:59 +00:00
|
|
|
style: StyleEngineProperties;
|
|
|
|
// String identifier for the font size preset--not an absolute value.
|
2023-05-12 12:42:16 +00:00
|
|
|
fontSize?: string | undefined;
|
2023-05-30 13:45:59 +00:00
|
|
|
// String identifier for the font family preset, not the actual font family.
|
2023-05-12 12:42:16 +00:00
|
|
|
fontFamily?: string | undefined;
|
|
|
|
};
|
|
|
|
|
2023-05-30 13:45:59 +00:00
|
|
|
export const useTypographyProps = ( props: blockAttributes ): StyleProps => {
|
|
|
|
const typography = isObject( props.style.typography )
|
|
|
|
? props.style.typography
|
2022-08-11 00:04:12 +00:00
|
|
|
: {};
|
2023-02-03 09:54:16 +00:00
|
|
|
const classNameFallback = isString( typography.fontFamily )
|
|
|
|
? typography.fontFamily
|
|
|
|
: '';
|
2023-05-12 12:42:16 +00:00
|
|
|
const className = props.fontFamily
|
|
|
|
? `has-${ props.fontFamily }-font-family`
|
2023-02-03 09:54:16 +00:00
|
|
|
: classNameFallback;
|
|
|
|
|
2022-08-11 00:04:12 +00:00
|
|
|
return {
|
2023-02-03 09:54:16 +00:00
|
|
|
className,
|
2022-08-11 00:04:12 +00:00
|
|
|
style: {
|
2023-05-12 12:42:16 +00:00
|
|
|
fontSize: props.fontSize
|
|
|
|
? `var(--wp--preset--font-size--${ props.fontSize })`
|
2022-08-11 00:04:12 +00:00
|
|
|
: typography.fontSize,
|
2022-12-12 14:53:42 +00:00
|
|
|
fontStyle: typography.fontStyle,
|
2023-02-03 09:54:16 +00:00
|
|
|
fontWeight: typography.fontWeight,
|
|
|
|
letterSpacing: typography.letterSpacing,
|
|
|
|
lineHeight: typography.lineHeight,
|
|
|
|
textDecoration: typography.textDecoration,
|
2022-08-11 00:04:12 +00:00
|
|
|
textTransform: typography.textTransform,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|