feat(createTypographyControl): add generic for identficator
This commit is contained in:
@@ -19,7 +19,9 @@ import {
|
|||||||
MIN_LINE_HEIGHT,
|
MIN_LINE_HEIGHT,
|
||||||
} from '../const/const';
|
} from '../const/const';
|
||||||
|
|
||||||
const controlData: ControlModel[] = [
|
export type ControlId = 'font_size' | 'font_weight' | 'line_height' | 'letter_spacing';
|
||||||
|
|
||||||
|
const controlData: ControlModel<ControlId>[] = [
|
||||||
{
|
{
|
||||||
id: 'font_size',
|
id: 'font_size',
|
||||||
value: DEFAULT_FONT_SIZE,
|
value: DEFAULT_FONT_SIZE,
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ export interface ControlDataModel {
|
|||||||
step: number;
|
step: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ControlModel extends ControlDataModel {
|
export interface ControlModel<T extends string = string> extends ControlDataModel {
|
||||||
/**
|
/**
|
||||||
* Control identifier
|
* Control identifier
|
||||||
*/
|
*/
|
||||||
id: string;
|
id: T;
|
||||||
/**
|
/**
|
||||||
* Area label for increase button
|
* Area label for increase button
|
||||||
*/
|
*/
|
||||||
@@ -59,10 +59,10 @@ export function createTypographyControl<T extends ControlDataModel>(
|
|||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
set value(newValue) {
|
set value(newValue) {
|
||||||
value = roundToStepPrecision(
|
const rounded = roundToStepPrecision(clampNumber(newValue, min, max), step);
|
||||||
clampNumber(newValue, min, max),
|
if (value !== rounded) {
|
||||||
step,
|
value = rounded;
|
||||||
);
|
}
|
||||||
},
|
},
|
||||||
get max() {
|
get max() {
|
||||||
return max;
|
return max;
|
||||||
|
|||||||
Reference in New Issue
Block a user