@srsa/svelte-components
v0.4.1
Published
Shared Svelte 5 component library for SRS Acquiom micro-frontends
Keywords
Readme
@srsa/svelte-components
Shared Svelte 5 component library for SRS Acquiom micro-frontends.
Installation
npm install @srsa/svelte-componentsPeer dependency: svelte ^5.0.0. Design tokens come from @srsa/ads-design-tokens.
Quick start
<script lang="ts">
import { Button, Chip } from '@srsa/svelte-components';
</script>
<Button variant="primary">Save</Button>
<Chip label="Active" variant="success" />Everything is exported from the package root. Each component also has a subpath export for tree-shaking:
import { Avatar } from '@srsa/svelte-components/Avatar';
import { useSortState } from '@srsa/svelte-components/utils/sort';Component index
Load only the doc for the component you need. Each file has the import, usage, props, test ids and gotchas.
| Component | Use it for | Docs |
| ------------------------- | ---------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| Avatar | Circular avatar with initials, image or fallback icon; optional tooltip | Avatar |
| Button | Button or link with variants (primary, secondary, tertiary, destructive) and icons | Button |
| Checkbox | Styled checkbox with label | Checkbox |
| Chip | Compact pill tag or badge with semantic color variants and sizes | Chip |
| DateBadge | Compact month/day date badge | DateBadge |
| ErrorBanner | Error alert with a refresh action | ErrorBanner |
| FileDropzone | Drag-and-drop file selection with validation | FileDropzone |
| Input | Text input with leading and trailing icon slots | Input |
| MultiSelectDropdown | Floating multi-select menu with a checkbox-style option list | MultiSelectDropdown |
| Pagination | Page size selector and prev/next navigation | Pagination |
| SelectDropdown | Native select with a chevron indicator | SelectDropdown |
| SortableColumnHeader | Clickable table sort header with a directional icon | SortableColumnHeader |
| TableCell | Table cell with alignment and emphasis variants | TableCell |
| TableRow | Interactive table row with selection state | TableRow |
| TableRowCount | Live-region row-count footer | TableRowCount |
| Toast + useToastState() | Auto-dismiss notification banner | Toast |
| Toggle | Toggle switch with label | Toggle |
| Tooltip | Hover/focus tooltip with auto-flip, portaled to document.body by default | Tooltip |
Composing a full table (rows, cells, sorting, pagination): Table.
Other exports:
| Export | Use it for | Docs |
| ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| useSortState, sortArray, compare* | Client-side table sorting | utils |
| formatCellValue, formatNumber, formatCurrency, formatDate, maskLast4, maskFull | Display formatting | utils |
| portal | Svelte action that moves a node to document.body (for your own overlays) | utils |
| CheckIcon, ChevronDownIcon, SortIcon | Icons used by the components | import { ChevronDownIcon } from '@srsa/svelte-components/icons' |
SCSS styles
@use '@srsa/svelte-components/styles/_tokens.scss' as tokens;
@use '@srsa/svelte-components/styles/_reset.scss' as *;
.my-component {
color: tokens.$color-brand-black;
font-family: tokens.$font-family-text;
@include reset;
}Development
npm install # Install dependencies
npm run dev # Dev server
npm test # Run tests
npm run test:unit # Run tests with coverage (fails under 90% lines; report in coverage/)
npm run package # Build package
npm run check # Type check
npm run lint # Lint (npm run lint:fix to autofix)
npm run format # Format with Prettier (npm run format:check to verify)
npm run storybook # Storybook on :6006Rules
These come from real problems we already fixed. Follow them so they stay fixed.
- Test ids. Every component takes
dataTestid?: string, rendered asdata-testid.- Inner parts derive from it:
${dataTestid}-<part>, per-item${dataTestid}-<part>-${value}. Derived ids are omitted (undefined) whendataTestidis unset. - Put
data-testidbefore{...restProps}so a rawdata-testidpassed by the consumer wins. - If rest props land on a wrapper but the interactive element is nested, add a
<part>Propspassthrough (e.g.triggerProps) spread before the component's ownaria-*and handlers, so the component's win. - List the derived parts in the
@componentheader and in the component's doc.
- Inner parts derive from it:
- One source tree. Components, icons, styles and utils live only under
src/lib/. Never create parallel top-levelsrc/components,src/icons,src/stylesorsrc/utilsfolders. We removed exactly that duplicate once. - New component checklist. Under
src/lib/components/<Name>/: the.sveltefile with an@componentheader, an exported<Name>Propstype,index.tsexporting the component and the type, the export insrc/lib/index.ts, apackage.jsonsubpath export, a*.stories.svelte, a spec, adocs/components/<Name>.md, and a row in the Component index above. - Tests. Specs go in
tests/unit/components/ortests/unit/utils/and import from../../../src/lib. CI fails under 90% line coverage. Content portaled todocument.body(MultiSelectDropdown panel, Tooltip bubble) must be queried withscreen, not the render container. UsefireEvent(there is nouser-event). jsdom has noelement.animate, so stub it when testing transitions. - Lint.
- Don't leave
svelte-ignorecomments the compiler no longer needs. - Don't use
{@html}on constant markup; inline the SVG instead. - Every
eslint-disableneeds a written reason and the narrowest scope. - Use
svelte/prefer-const, not coreprefer-const, in.sveltefiles (already configured).
- Don't leave
- Packaging.
package.jsonexportsandfilesmust point atdist/, neversrc/. Runnpm run packageandnpm pack --dry-runafter touching them. - Docs. Keep this README thin: it describes the project and routes to docs. Component details belong in
docs/components/<Name>.md. Update that file in the same change that alters a component's props or test ids. - CI gates.
check,lint,format:check,test:unitandauditare all required. Runnpm run formatbefore committing. Don't addcontinue-on-error.
