This repo follows the NI JavaScript and TypeScript Styleguide with the following exceptions.
In order to present consistent APIs with FAST and follow modern TypeScript practices, this package doesn't use TypeScript enums.
Instead of this enum:
const enum ButtonAppearance {
Outline = 'outline',
Ghost = 'ghost',
Block = 'outblockline',
}You can use a const object for the enum and a union of its values for the type:
export const ButtonAppearance = {
outline: 'outline',
ghost: 'ghost',
block: 'block'
} as const;
export type ButtonAppearance = typeof ButtonAppearance[keyof typeof ButtonAppearance];Put these objects in a file called types.ts to make them easier to find and to apply an ESLint configuration that is specific to this pattern. Add a corresponding types.spec.ts to ensure the pattern is applied correctly.
To clients, the object and values will behave like an enum:
import { ButtonAppearance from '../types.ts' }
let appearance: ButtonAppearance = ButtonAppearance.outline;If one of the enum values represents a default, it should be named default and be the first enumerated value.
export const BannerSeverity = {
default: undefined,
error: 'error',
warning: 'warning',
information: 'information'
} as const;When defining new class names in HTML, use kebab case.
<div class="control-wrapper"> <!-- CORRECT -->
<div class="controlWrapper"> <!-- INCORRECT -->