Skip to content
Snippets Groups Projects
Commit 2c253760 authored by Loïc Correnson's avatar Loïc Correnson Committed by Michele Alberti
Browse files

[dome] utils

parent f46225aa
No related branches found
No related tags found
No related merge requests found
...@@ -2,12 +2,41 @@ ...@@ -2,12 +2,41 @@
// --- Utilities // --- Utilities
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/**
@packageDocumentation
@module dome/misc/utils
*/
import type { CSSProperties } from 'react'; import type { CSSProperties } from 'react';
export type ClassSpec = type falsy = undefined | boolean | null | '';
undefined | boolean | null | string |
{ [cname: string]: boolean | null | undefined }; export type ClassSpec = string | falsy | { [cname: string]: true | falsy };
/**
Utility function to merge various HTML class properties
into a `className` property.
Class specifications can be made of:
- a string, interpreted as a CSS class specification
- an object, with keys corresponding to CSS class associated
to true of falsy value.
- any falsy value, which is discarded
Example of usage:
* ```ts
* const className = classes(
* 'my-base-class',
* condition && 'my-class-when-condition',
* {
* 'my-class-1': cond-1,
* 'my-class-2': cond-2,
* 'my-class-3': cond-3,
* }
* );
* ```
*/
export function classes( export function classes(
...args: ClassSpec[] ...args: ClassSpec[]
): string { ): string {
...@@ -24,8 +53,25 @@ export function classes( ...@@ -24,8 +53,25 @@ export function classes(
return buffer.join(' '); return buffer.join(' ');
} }
export type StyleSpec = export type StyleSpec = falsy | CSSProperties;
undefined | boolean | null | CSSProperties;
/**
Utility function to merge various CSS style properties
into a single CSS style object.
Each style specification can be made of a CSS object or (discarded)
falsy values.
Example of usage:
* ```ts
* const sty = styles(
* { ... },
* cond-1 && { ... },
* cond-2 && { ... },
* );
* ```
*/
export function styles( export function styles(
...args: StyleSpec[] ...args: StyleSpec[]
......
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
"doc/pages", "doc/pages",
"src/frama-c", "api", "src/frama-c", "api",
"src/dome/src/renderer", "src/dome/src/renderer",
"src/dome/src/misc",
] ]
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment