Scalars component library
npm install @scalar/components




Scalar Components provides a library of components used across Scalar products. The library is designed to work seamlessly with our theming system and includes a scoped copy of the themes reset, base variables and colors.
Want to explore the components? Check out the Storybook for a live demo.
``bash`
pnpm i @scalar/components
Because many Scalar applications are embedded into other websites the components reset and styles are scoped to the scalar-app class. This means you need to add this class to the root element of your application where you want the to use the components. If you are using the components in a standalone application, you can just add this class to the body element.
`html`
To get started, import the CSS styles in your main setup file (e.g., main.ts, index.ts, or App.vue):
`ts`
import '@scalar/components/style.css'
Then, you can use the components in your Vue components. For example:
`html`
setup
lang="ts">
import { ScalarButton } from '@scalar/components'
Most components can be customized using props. For example, the ScalarButton component can be customized with the variant prop to change the variant of the button.
`html`
However, sometimes you need to override the default styles. Most components (soon to be all) use the useBindCx function to apply the Tailwind classes to the component. The function intelligently merges the component's classes with the provided classes allowing you to override preset classes.
`html`
This will apply the h-24 w-48 classes to the button and remove the sizing classes that would normally be applied by default. For more information see the useBindCx function.
The component library includes a number of floating components including the ScalarPopover, ScalarDropdown, and ScalarListbox as well as a ScalarFloating primitive. All of the components use Floating UI under the hood and provide the same for interacting with the Floating UI API.
When using the floating components the default slot renders reference / target element (e.g. a button) and a named slot renders the floating element (e.g. a menu). For example:
`html`
Since you can directly target the reference element with Tailwind classes any classes applied to the base component will be applied to the floating element (using useBindCx under the hood). For example:
`html`
...
The components package uses the same CSS Layers as the themes package to apply the theme styles. For more information see the themes README.
The components library uses both unit testing (vitest) and snapshot testing to ensure quality and visual consistency. Snapshot tests are written using Playwright and capture screenshots of Storybook stories to detect visual regressions.
For detailed information about the testing setup, see the test README.
All pull requests should include the following checklist:
`mdComponent Checklist
- [ ] Exported from @scalar/components``
- [ ] Has JSDocs for all:
- [ ] Components (with examples)
- [ ] Props
- [ ] Slots
- [ ] Emits
- [ ] Functions
- [ ] Types
- [ ] Allows overriding of Tailwind classes where applicable (see useBindCx)
- [ ] Has stories showcasing any applicable variants
- [ ] Has unit tests covering any applicable interactions
- [ ] Has snapshot tests covering any visual variations