finish custom class and improved options overhaul
This commit is contained in:
@@ -15,3 +15,31 @@ export const generateIdentifier = (prefix?: string, identifier?: string): string
|
||||
const timestampPart = Date.now().toString(36);
|
||||
return `${prefix ? prefix + '-' : ''}${randomPart}-${timestampPart}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Option type definition for a select option. Used in various components.
|
||||
*/
|
||||
export type Option =
|
||||
| {
|
||||
value: string;
|
||||
label?: string;
|
||||
}
|
||||
| string;
|
||||
|
||||
/** getLabel returns the option label if it exists*/
|
||||
export const getLabel = (option: Option): string => {
|
||||
if (typeof option === 'string') {
|
||||
return option;
|
||||
} else {
|
||||
return option.label ?? option.value;
|
||||
}
|
||||
};
|
||||
|
||||
/** getValue returns the option value */
|
||||
export const getValue = (option: Option): string => {
|
||||
if (typeof option === 'string') {
|
||||
return option;
|
||||
} else {
|
||||
return option.value;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user