Skip to content

Commit

Permalink
add new link option for pills (viamrobotics#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrloureed authored Jul 3, 2024
1 parent 23ef504 commit 4b60729
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 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.127",
"version": "0.0.128",
"publishConfig": {
"access": "public"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/lib/__tests__/pill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ describe('Pill', () => {
render(Pill, { value: 'test', cx: cxTestArguments });
expect(screen.getByText('test').parentElement).toHaveClass(cxTestResults);
});

it('Renders with the passed href', () => {
render(Pill, { value: 'link', href: 'https://www.viam.com' });
expect(screen.getByRole('link', { name: 'link' })).toHaveAttribute(
'href',
'https://www.viam.com'
);
});
});
16 changes: 15 additions & 1 deletion packages/core/src/lib/pill.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { createEventDispatcher } from 'svelte';
/** The text in the pill. */
export let value = '';
/** Optional URL that the hyperlink points to. */
export let href = '';
/** Optional target for linked URL. */
export let target: '_self' | '_blank' | '_parent' | '_top' = '_blank';
/** Whether or not the pill has the aria-readonly attribute. If readonly, there is not a button to remove the pill. */
export let readonly = false;
Expand Down Expand Up @@ -69,7 +75,15 @@ const handleRemove = () => {
size="sm"
/>
{/if}
<span class="truncate">{value}</span>
{#if href}
<a
{href}
{target}
class="truncate hover:underline">{value}</a
>
{:else}
<span class="truncate">{value}</span>
{/if}
{#if !readonly && removable}
<button
type="button"
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,18 @@ const onHoverDelayMsInput = (event: Event) => {
icon="viam-component"
removable={false}
/>
<Pill
value="my-machine-123"
icon="multiplication-box"
href="https://i.imgur.com/aQCBxdr.png"
removable={false}
/>
<Pill
value="target-self-example"
href="https://i.imgur.com/aQCBxdr.png"
target="_self"
removable={false}
/>
</div>

<!-- Prevent Handler -->
Expand Down
4 changes: 4 additions & 0 deletions packages/storybook/src/stories/pill.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ import { Pill } from '@viamrobotics/prime-core';
<Canvas>
<Story of={PillStories.IconNotRemovable} />
</Canvas>

<Canvas>
<Story of={PillStories.Link} />
</Canvas>
17 changes: 17 additions & 0 deletions packages/storybook/src/stories/pill.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,20 @@ import { Pill } from '@viamrobotics/prime-core';
/>
</div>
</Story>

<Story name="Link">
<div class="flex flex-row gap-1.5">
<Pill
value="my-machine-123"
icon="multiplication-box"
href="https://i.imgur.com/aQCBxdr.png"
removable={false}
/>
<Pill
value="target-self-example"
href="https://i.imgur.com/aQCBxdr.png"
target="_self"
removable={false}
/>
</div>
</Story>

0 comments on commit 4b60729

Please sign in to comment.