Skip to content

Commit

Permalink
2024-01-10 PRIME design maintenance (viamrobotics#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanlookpotts authored Jan 17, 2024
1 parent 3643cac commit db1be63
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 89 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/prime-core",
"version": "0.0.83",
"version": "0.0.84",
"publishConfig": {
"access": "public"
},
Expand Down
11 changes: 1 addition & 10 deletions packages/core/src/lib/__tests__/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,11 @@ describe('Radio', () => {
expect(screen.getByText('Test radio options')).toBeVisible();
});

it('Renders the legend correctly when disabled', () => {
render(Radio, { ...common, disabled: true });

const legend = screen.getByText('Test radio options');
expect(legend).toHaveClass('text-disabled-dark cursor-not-allowed');
});

it('Renders the legend correctly when required', () => {
render(Radio, { ...common, required: true });

const legend = screen.getByText('Test radio options');
expect(legend).toHaveClass(
'after:ml-1 after:text-danger-dark after:content-["*"]'
);
expect(legend).toHaveClass('after:text-danger-dark after:content-["*"]');
});

it('Renders in a row if specified', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/input/numeric-input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $: pattern = isNumber ? '^([-+,0-9.]+)' : '[0-9]+';
{pattern}
{step}
{...$$restProps}
placeholder={$$restProps.placeholder ?? 0}
bind:value
bind:input
on:input
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/lib/radio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ $: getIcon = (option: string): IconName =>
{#if $$slots.legend}
<legend
class={cx(
cx('mb-1 flex text-xs', {
'text-subtle-1': !disabled,
'cursor-not-allowed text-disabled-dark': disabled,
'after:ml-1 after:text-danger-dark after:content-["*"]': required,
cx('mb-1 flex text-xs text-subtle-1', {
'after:text-danger-dark after:content-["*"]': required,
})
)}
>
Expand Down Expand Up @@ -105,9 +103,11 @@ $: getIcon = (option: string): IconName =>
name={getIcon(option)}
cx={cx({
'text-disabled-dark': disabled,
'text-gray-9': !disabled && option === selected,
'text-gray-6': !disabled && option !== selected,
})}
/>
<span class="pl-1.5 peer-focus:underline">
<span class="pl-1.5">
{option}
</span>
</Label>
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook/src/stories/input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ An opinionated input for text values that only allows specified regex. The allow
import { RestrictedTextInput } from '@viamrobotics/prime-core';

const restrictInput = (inputValue: string) =>
inputValue.replaceAll(/[^a-n]/gu, '');
inputValue.replaceAll(/[^a-zA-Z0-9]/gu, '');
```

<Canvas>
Expand Down
27 changes: 17 additions & 10 deletions packages/storybook/src/stories/input.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@viamrobotics/prime-core';
const restrictInput = (inputValue: string) =>
inputValue.replaceAll(/[^a-n]/gu, '');
inputValue.replaceAll(/[^a-zA-Z0-9]/gu, '');
</script>

<Meta title="Elements/Input" />
Expand All @@ -34,21 +34,28 @@ const restrictInput = (inputValue: string) =>
</Story>

<Story name="Restricted Text">
<div class="mb-2 max-w-[200px]">
<RestrictedTextInput
value=""
{restrictInput}
tooltipDescription="Only lowercase a-n allowed"
/>
</div>
<Label>
Username
<div
slot="input"
class="mb-2 max-w-[200px]"
>
<RestrictedTextInput
value=""
{restrictInput}
tooltipDescription="Valid characters: letters, numbers"
placeholder="funkymonkey89"
/>
</div>
</Label>
</Story>

<Story name="Numeric">
<NumericInput cx="max-w-[200px]" />
<NumericInput cx="max-w-[80px]" />
</Story>

<Story name="Slider">
<SliderInput cx="max-w-[200px]" />
<SliderInput cx="max-w-[80px]" />
</Story>

<Story name="Range">
Expand Down
4 changes: 3 additions & 1 deletion packages/storybook/src/stories/label.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ import { Label } from '@viamrobotics/prime-core';
```

<Canvas>
<Story of={LabelStories.Basic} />
<Story of={LabelStories.Input} />
</Canvas>

TODO(ethanlook): add other input types here!
4 changes: 2 additions & 2 deletions packages/storybook/src/stories/modal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { Modal } from '@viamrobotics/prime-core';
```

<Canvas>
<Story of={ModalStories.Default} />
<Story of={ModalStories.Small} />
</Canvas>

<Canvas>
<Story of={ModalStories.Small} />
<Story of={ModalStories.Default} />
</Canvas>
37 changes: 20 additions & 17 deletions packages/storybook/src/stories/modal.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ let smallModalOpen = false;

<Meta title="Elements/Modal" />

<Story name="Default">
<div class="h-[500px]">
<Button on:click={() => (defaultModalOpen = true)}>Open</Button>
<Story name="Small">
<div class="h-[200px]">
<Button on:click={() => (smallModalOpen = true)}>Open</Button>
<Modal
isOpen={defaultModalOpen}
on:close={() => (defaultModalOpen = false)}
isOpen={smallModalOpen}
variant="small"
on:close={() => (smallModalOpen = false)}
>
<svelte:fragment slot="title">Default title</svelte:fragment>
<svelte:fragment slot="message"
>This is the default modal.</svelte:fragment
>
<svelte:fragment slot="title">Small modal title</svelte:fragment>
<svelte:fragment slot="message">This is a small modal.</svelte:fragment>
<Button
slot="primary"
on:click={() => console.log('Primary button clicked')}
Expand All @@ -36,16 +35,20 @@ let smallModalOpen = false;
</div>
</Story>

<Story name="Small">
<div class="h-[200px]">
<Button on:click={() => (smallModalOpen = true)}>Open</Button>
<Story name="Default">
<div class="h-[500px]">
<Button on:click={() => (defaultModalOpen = true)}>Open</Button>
<Modal
isOpen={smallModalOpen}
variant="small"
on:close={() => (smallModalOpen = false)}
isOpen={defaultModalOpen}
on:close={() => (defaultModalOpen = false)}
>
<svelte:fragment slot="title">Small modal title</svelte:fragment>
<svelte:fragment slot="message">This is a small modal.</svelte:fragment>
<svelte:fragment slot="title">Default title</svelte:fragment>
<div
slot="message"
class="h-full border border-dashed border-light"
>
This is a large modal.
</div>
<Button
slot="primary"
on:click={() => console.log('Primary button clicked')}
Expand Down
17 changes: 14 additions & 3 deletions packages/storybook/src/stories/pill.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@ import * as PillStories from './pill.stories.svelte';

# Pill

Displays a pill.
There are two types of pills, `default` (no icon) and `outlined` (icon).
Either type can be removable or read-only.

The `outlined` variant should be used to represent objects within Viam
like components, services, machines, fragments, etc. The icon should be
the appropriate icon for the object type and the text should be the
user-defined name of the object (ie. the machine name, component name,
etc).

```ts
import { Pill } from '@viamrobotics/prime-core';
```

<Canvas>
<Story of={PillStories.Primary} />
<Story of={PillStories.Default} />
</Canvas>

<Canvas>
<Story of={PillStories.Unremovable} />
<Story of={PillStories.DefaultNotRemovable} />
</Canvas>

<Canvas>
<Story of={PillStories.Outlined} />
</Canvas>

<Canvas>
<Story of={PillStories.OutlinedNotRemovable} />
</Canvas>
74 changes: 61 additions & 13 deletions packages/storybook/src/stories/pill.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,70 @@ import { Pill } from '@viamrobotics/prime-core';

<Meta title="Elements/Pill" />

<Story name="Primary">
<Pill value="cool pill" />
<Story name="Default">
<div class="flex flex-row gap-1.5">
<Pill value="Lion" />
<Pill value="Tiger" />
<Pill value="Bear" />
</div>
</Story>

<Story name="Unremovable">
<Pill
value="Not removable"
readonly
/>
<Story name="Default Not Removable">
<div class="flex flex-row gap-1.5">
<Pill
value="Lion"
removable={false}
/>
<Pill
value="Tiger"
removable={false}
/>
<Pill
value="Bear"
removable={false}
/>
</div>
</Story>

<Story name="Outlined">
<Pill
value="Viam resource"
variant="outlined"
icon="viam-service"
removable={false}
/>
<div class="flex flex-row gap-1.5">
<Pill
value="my-base"
variant="outlined"
icon="viam-component"
/>
<Pill
value="my-movement-sensor"
variant="outlined"
icon="viam-component"
/>
<Pill
value="my-nav-service"
variant="outlined"
icon="viam-service"
/>
</div>
</Story>

<Story name="Outlined Not Removable">
<div class="flex flex-row gap-1.5">
<Pill
value="my-base"
variant="outlined"
icon="viam-component"
removable={false}
/>
<Pill
value="my-movement-sensor"
variant="outlined"
icon="viam-component"
removable={false}
/>
<Pill
value="my-nav-service"
variant="outlined"
icon="viam-service"
removable={false}
/>
</div>
</Story>
4 changes: 0 additions & 4 deletions packages/storybook/src/stories/radio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ import { Radio } from '@viamrobotics/prime-core';
<Canvas>
<Story of={RadioStories.Disabled} />
</Canvas>

<Canvas>
<Story of={RadioStories.Row} />
</Canvas>
33 changes: 11 additions & 22 deletions packages/storybook/src/stories/radio.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,39 @@ import { Radio } from '@viamrobotics/prime-core';
<Story name="Basic">
<Radio
name="basic"
options={['Opt 1', 'Opt 2', 'Opt 3']}
selected="Opt 1"
options={['Lion', 'Tiger', 'Bear']}
selected="Lion"
/>
</Story>

<Story name="With legend">
<Radio
name="legend"
options={['Opt 1', 'Opt 2']}
selected="Opt 1"
options={['Lion', 'Tiger', 'Bear']}
selected="Lion"
>
<svelte:fragment slot="legend">These are your options</svelte:fragment>
<svelte:fragment slot="legend">Favorite animal</svelte:fragment>
</Radio>
</Story>

<Story name="Required">
<Radio
name="required"
options={['To be', 'Not to be']}
selected="Opt 1"
options={['Lion', 'Tiger', 'Bear']}
selected="Lion"
required
>
<svelte:fragment slot="legend">Answer the question</svelte:fragment>
<svelte:fragment slot="legend">Favorite animal</svelte:fragment>
</Radio>
</Story>

<Story name="Disabled">
<Radio
name="disabled"
options={['Frank', 'Dave']}
selected="Frank"
options={['Lion', 'Tiger', 'Bear']}
selected="Lion"
disabled
>
<svelte:fragment slot="legend"
>I'm afraid that's something I cannot allow to happen.
</svelte:fragment>
<svelte:fragment slot="legend">Favorite animal</svelte:fragment>
</Radio>
</Story>

<Story name="Row">
<Radio
name="row"
options={['Left', 'Right']}
selected="Left"
direction="row"
/>
</Story>

0 comments on commit db1be63

Please sign in to comment.