Skip to content

Theming ​

Introduction ​

@nepdatejs/styles is plain CSS: no Tailwind and no build step. Everything is drawn with --ndp-* CSS variables, so you can match your design by overriding a few of them.

ts
import '@nepdatejs/styles';

Your brand colour ​

Set these on :root, after the stylesheet has loaded:

css
:root {
  --ndp-bg-accent: #126453;
  --ndp-border-accent: #126453;
  --ndp-text-accent: #126453;
  --ndp-bg-accent-muted: #e5eee6;
  --ndp-text-on-accent-muted: #0b3f35;
  --ndp-focus-ring: rgb(18 100 83 / 0.5);
}

To theme one picker, set them on a wrapper instead of :root.

Dark mode ​

By default the components follow the system's light or dark setting. To force one, use the data-ndp-theme attribute on <html> or on any wrapper:

html
<html data-ndp-theme="dark">
  <body>
    <div data-ndp-theme="light">
      <nep-date-picker></nep-date-picker>
    </div>
  </body>
</html>

Or pass theme to a component:

tsx
<DatePicker theme="dark" />;
html
<nep-date-picker theme="dark"></nep-date-picker>

theme accepts light, dark or auto.

If your app has its own theme switch, set the attribute from it:

ts
function setDark(dark: boolean) {
  document.documentElement.dataset['ndpTheme'] = dark ? 'dark' : 'light';
}

setDark(true);

Tokens ​

Colours ​

TokenUsed for
--ndp-bg-surfacePanel and input background
--ndp-bg-mutedSegment background
--ndp-bg-hoverHovered days and buttons
--ndp-bg-accentSelected day, primary button
--ndp-bg-accent-mutedThe middle of a range
--ndp-bg-holiday-mutedHoliday background
--ndp-border-defaultDividers and panel border
--ndp-border-strongInput border
--ndp-border-hoverInput border on hover
--ndp-border-accentFocused input, today
--ndp-border-dangerAn invalid input
--ndp-text-primaryMain text
--ndp-text-secondaryLabels
--ndp-text-mutedHints and the other calendar's digits
--ndp-text-disabledDisabled days
--ndp-text-accentLinks and today
--ndp-text-on-accentText on a selected day
--ndp-text-on-accent-mutedText in the middle of a range
--ndp-text-holidayHolidays and weekends
--ndp-text-dangerError messages
--ndp-focus-ringKeyboard focus outline

Sizes ​

TokenDefaultUsed for
--ndp-day-size44pxA day cell
--ndp-input-height40pxThe input
--ndp-icon-button-size32pxIcon buttons
--ndp-option-height48pxMonth and year tiles
--ndp-panel-padding12pxPanel padding
--ndp-presets-width152pxThe shortcut list

Shape and type ​

TokenDefault
--ndp-radius-sm6px
--ndp-radius-md8px
--ndp-radius-lg12px
--ndp-space-4, --ndp-space-8, --ndp-space-124px, 8px, 12px
--ndp-fontInter, then the system font
--ndp-shadow-panelThe panel's shadow
--ndp-z-index50, used when the browser has no top layer

Keeping contrast ​

Each text colour meets WCAG AA against its background, in both themes. If you change colours, check them again, especially --ndp-text-on-accent on --ndp-bg-accent.

Using only the tokens ​

To reuse the variables in your own CSS without the component styles:

ts
import '@nepdatejs/styles/tokens.css';

Released under the MIT licence.