Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 1.75 KB

File metadata and controls

59 lines (43 loc) · 1.75 KB

Coding Conventions

This repo follows the NI JavaScript and TypeScript Styleguide with the following exceptions.

Use const objects instead of TypeScript enums

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;

Default enum values

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;

Use kebab case for class names

When defining new class names in HTML, use kebab case.

<div class="control-wrapper"> <!-- CORRECT -->
<div class="controlWrapper"> <!-- INCORRECT -->