@gechiui/components
Version:
UI components for GeChiUI.
102 lines • 4.24 kB
TypeScript
/**
* Internal dependencies
*/
import type { Value, GCUnitControlUnit, GCUnitControlUnitList } from './types';
/**
* An array of all available CSS length units.
*/
export declare const ALL_CSS_UNITS: GCUnitControlUnit[];
/**
* Units of measurements. `a11yLabel` is used by screenreaders.
*/
export declare const CSS_UNITS: GCUnitControlUnit[];
export declare const DEFAULT_UNIT: GCUnitControlUnit;
/**
* Handles legacy value + unit handling.
* This component use to manage both incoming value and units separately.
*
* Moving forward, ideally the value should be a string that contains both
* the value and unit, example: '10px'
*
* @param value Value
* @param unit Unit value
* @param units Units to derive from.
* @return The extracted number and unit.
*/
export declare function getParsedValue(value: Value, unit?: string, units?: GCUnitControlUnitList): [Value, string | undefined];
/**
* Checks if units are defined.
*
* @param units Units to check.
* @return Whether units are defined.
*/
export declare function hasUnits(units: GCUnitControlUnitList): boolean;
/**
* Parses a number and unit from a value.
*
* @param initialValue Value to parse
* @param units Units to derive from.
* @return The extracted number and unit.
*/
export declare function parseUnit(initialValue: Value | undefined, units?: GCUnitControlUnitList): [Value, string | undefined];
/**
* Parses a number and unit from a value. Validates parsed value, using fallback
* value if invalid.
*
* @param next The next value.
* @param units Units to derive from.
* @param fallbackValue The fallback value.
* @param fallbackUnit The fallback value.
* @return The extracted value and unit.
*/
export declare function getValidParsedUnit(next: Value | undefined, units: GCUnitControlUnitList, fallbackValue: Value, fallbackUnit: string | undefined): [Value, string | undefined];
/**
* Takes a unit value and finds the matching accessibility label for the
* unit abbreviation.
*
* @param unit Unit value (example: px)
* @return a11y label for the unit abbreviation
*/
export declare function parseA11yLabelForUnit(unit: string): string | undefined;
/**
* Filters available units based on values defined by the unit setting/property.
*
* @param unitSetting Collection of preferred unit value strings.
* @param units Collection of available unit objects.
*
* @return Filtered units based on settings.
*/
export declare function filterUnitsWithSettings(unitSetting: string[] | undefined, units: GCUnitControlUnitList): Array<GCUnitControlUnit>;
/**
* Custom hook to retrieve and consolidate units setting from add_theme_support().
* TODO: ideally this hook shouldn't be needed
* https://github.com/GeChiUI/gutenberg/pull/31822#discussion_r633280823
*
* @param args An object containing units, settingPath & defaultUnits.
* @param args.units Collection of all potentially available units.
* @param args.availableUnits Collection of unit value strings for filtering available units.
* @param args.defaultValues Collection of default values for defined units. Example: { px: '350', em: '15' }.
*
* @return Filtered units based on settings.
*/
export declare const useCustomUnits: ({ units, availableUnits, defaultValues, }: {
units?: GCUnitControlUnitList | undefined;
availableUnits?: string[] | undefined;
defaultValues: Record<string, Value>;
}) => GCUnitControlUnitList;
/**
* Get available units with the unit for the currently selected value
* prepended if it is not available in the list of units.
*
* This is useful to ensure that the current value's unit is always
* accurately displayed in the UI, even if the intention is to hide
* the availability of that unit.
*
* @param currentValue Selected value to parse.
* @param legacyUnit Legacy unit value, if currentValue needs it appended.
* @param units List of available units.
*
* @return A collection of units containing the unit for the current value.
*/
export declare function getUnitsWithCurrentUnit(currentValue: Value, legacyUnit: string | undefined, units?: GCUnitControlUnitList): GCUnitControlUnitList;
//# sourceMappingURL=utils.d.ts.map