0.0.117 • Published 1 day ago

@viamrobotics/prime-core v0.0.117

Weekly downloads
-
License
-
Repository
-
Last release
1 day ago

@viamrobotics/prime-core

Getting started

@viamrobotics/prime-core is a collection of core Svelte components.

Installation

Add PRIME core using your package manager of choice:

pnpm add --save-dev @viamrobotics/prime-core

Install Tailwind. In the tailwind.config.js, add the components to the content and include the theme:

import { theme } from '@viamrobotics/prime-core/theme';
import { plugins } from '@viamrobotics/prime-core/plugins';

/** @type {import('tailwindcss').Config} */
export default {
  content: [
    './src/**/*.{html,js,svelte,ts}',
    './node_modules/@viamrobotics/prime-core/**/*.{ts,svelte}',
  ],
  theme,
  plugins,
};

Import the stylesheet. If you are using SvelteKit, you can do this in src/routes/+layout.svelte.

import '@viamrobotics/prime-core/prime.css';

You can now use the components in your app:

<script lang="ts">
  import { Badge } from '@viamrobotics/prime-core';
</script>

<Badge
  variant="green"
  label="Active"
/>

Playground

The playground can be used during development but is not used outside of the package.

pnpm install
pnpm -C packages/core dev

Linting

To lint and typecheck:

pnpm -C packages/core check        # check svelte and lint
pnpm -C packages/core check-svelte # check svelte only
pnpm -C packages/core check-lint   # check lint only with prettier and eslint
pnpm -C packages/core format       # format with prettier

Testing

To test with vitest:

pnpm -C packages/core test        # run once
pnpm -C packages/core test:watch  # watch tests

Anatomy of a Component

For easier readability, we try to use a standard ordering for component composition. These are not strict rules, but more a guideline to follow. Implementation specifics may force you to go outside this guideline.

<!-- svelte options: https://svelte.dev/docs/special-elements#svelte-options -->
<svelte:options immutable />

<script
  lang="ts"
  context="module"
>
  // exported types
  export type MyType = 'thing' | 'other-thing';
</script>

<script lang="ts">
  // external imports
  import { onMount, createEventDispatcher } from 'svelte';

  // internal imports
  import { someLibraryFunction } from '$lib';
  import { someSiblingFunction } from './sibling';

  // prop declarations
  /** A doc string for prop explaining what it does. */
  export let prop: MyType | undefined = undefined;

  // event dispatchers and other hooks
  const dispatcher = createEventDispatcher<{
    /** A doc string for the event handler. */
    click: null; // void event
    /** A doc string for the event handler. */
    primitive: string | number | boolean; // simple primitive values
    /** A doc string for the event handler. */
    object: { id: string; next: number; }; // complex values
    /** A doc string for the event handler. */
    native: Event // native events (for pure atoms)
  }>()

  // internal fields
  let someString = '';

  // reactive variables
  $: isThing = prop === 'thing';

  // complex reactive variables
  let counter = 0;
  $: if (isThing) {
      counter = someString.length;
      if (counter > 10) {
        counter = 10;
      }
  }

  // single-line functions
  const doSomething = () => someLibraryFunction();

  // multi-line functions
  const doSomethingElse = () => {
    const shouldDoSomething = someString !== '';
    someSiblingFunction(shouldDoSomething);
  }

  // reactive statements
  $: {
    someString = prop ? 'whoa' : 'no';
  }

  // lifecycle hooks
  onMount(() => ...);
</script>

<!-- Your layout -->
<div class="border-black">
  <!-- 
    all slots should be named if there are multiple; otherwise a single slot 
    can be the default `<slot />`  
  -->
  <slot name="title" />
  <slot name="content" />
</div>

<style>
  /* custom styles */
</style>

Tests and Test Components

We keep tests in a __tests__ directory that is a sibling of the code being tested. These directories should only contain tests and test components.

Some components require test components to render slotted children, due to limitations with rendering slots using @testing-library.

See:

0.0.117

1 day ago

0.0.116

2 days ago

0.0.115

13 days ago

0.0.114

15 days ago

0.0.113

17 days ago

0.0.109

21 days ago

0.0.112

21 days ago

0.0.111

21 days ago

0.0.110

21 days ago

0.0.108

22 days ago

0.0.106

24 days ago

0.0.107

24 days ago

0.0.105

27 days ago

0.0.104

27 days ago

0.0.103

1 month ago

0.0.102

1 month ago

0.0.101

1 month ago

0.0.100

1 month ago

0.0.99

1 month ago

0.0.98

2 months ago

0.0.96

2 months ago

0.0.97

2 months ago

0.0.95

2 months ago

0.0.94

2 months ago

0.0.93

2 months ago

0.0.91

3 months ago

0.0.92

3 months ago

0.0.90

3 months ago

0.0.89

3 months ago

0.0.88

3 months ago

0.0.86

3 months ago

0.0.87

3 months ago

0.0.85

3 months ago

0.0.84

4 months ago

0.0.82

4 months ago

0.0.83

4 months ago

0.0.81

4 months ago

0.0.80

4 months ago

0.0.79

4 months ago

0.0.77

4 months ago

0.0.78

4 months ago

0.0.76

5 months ago

0.0.74

5 months ago

0.0.75

5 months ago

0.0.73

5 months ago

0.0.71

5 months ago

0.0.72

5 months ago

0.0.70

5 months ago

0.0.69

5 months ago

0.0.68

5 months ago

0.0.67

5 months ago

0.0.66

5 months ago

0.0.64

6 months ago

0.0.63

6 months ago

0.0.62

6 months ago

0.0.61

6 months ago

0.0.60

6 months ago

0.0.59

6 months ago

0.0.58

6 months ago

0.0.57

6 months ago

0.0.56

7 months ago

0.0.55

7 months ago

0.0.54

7 months ago

0.0.53

7 months ago

0.0.52

7 months ago

0.0.51

7 months ago

0.0.50

7 months ago

0.0.49

7 months ago

0.0.48

7 months ago

0.0.47

7 months ago

0.0.46

7 months ago

0.0.45

7 months ago

0.0.44

7 months ago

0.0.43

7 months ago

0.0.42

7 months ago

0.0.41

7 months ago

0.0.40

8 months ago

0.0.39

8 months ago

0.0.38

8 months ago

0.0.37

8 months ago

0.0.36

8 months ago

0.0.35

8 months ago

0.0.34

8 months ago

0.0.33

8 months ago

0.0.32

8 months ago

0.0.31

8 months ago

0.0.30

8 months ago

0.0.29

8 months ago

0.0.28

8 months ago

0.0.27

8 months ago

0.0.26

8 months ago

0.0.25

8 months ago

0.0.24

8 months ago

0.0.23

8 months ago

0.0.22

8 months ago

0.0.21

8 months ago

0.0.20

8 months ago

0.0.19

8 months ago

0.0.18

9 months ago

0.0.17

9 months ago

0.0.16

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

10 months ago