-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
433 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/core/src/lib/context-menu/context-menu-separator.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
<!-- | ||
@component | ||
A horizontal line divider within a context menu. | ||
```svelte | ||
<ContextMenuSeparator /> | ||
``` | ||
--> | ||
<svelte:options immutable /> | ||
|
||
<hr class="mb-0.5 mt-1 border-light drop-shadow-none" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!-- | ||
@component | ||
This component allows us to render a Table with its slotted | ||
children, due to limitations with rendering slots using | ||
`@testing-library`. | ||
See: | ||
- https://sveltesociety.dev/recipes/testing-and-debugging/unit-testing-svelte-component | ||
- https://github.com/testing-library/svelte-testing-library/issues/48 | ||
--> | ||
<script lang="ts"> | ||
import Table from './table.svelte'; | ||
import TBody from './tbody.svelte'; | ||
import TR from './tr.svelte'; | ||
import TD from './td.svelte'; | ||
export let cols: string[] = []; | ||
</script> | ||
|
||
<Table {cols}> | ||
<TBody> | ||
<TR> | ||
<TD>stuff</TD> | ||
<TD>stuffs</TD> | ||
<TD>stufffss</TD> | ||
</TR> | ||
</TBody> | ||
</Table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { render, screen } from '@testing-library/svelte'; | ||
import Table from './table.svelte'; | ||
import TableWith3Cols from './table.spec.svelte'; | ||
|
||
describe('Table', () => { | ||
it('Renders default variant', () => { | ||
render(Table); | ||
expect(screen.getByRole('table')).toBeVisible(); | ||
expect(screen.getByRole('table')).toHaveClass('table-auto'); | ||
}); | ||
|
||
it('Renders auto variant', () => { | ||
render(Table, { variant: 'auto' }); | ||
expect(screen.getByRole('table')).toBeVisible(); | ||
expect(screen.getByRole('table')).toHaveClass('table-auto'); | ||
}); | ||
|
||
it('Renders fixed variant', () => { | ||
render(Table, { variant: 'fixed' }); | ||
expect(screen.getByRole('table')).toBeVisible(); | ||
expect(screen.getByRole('table')).toHaveClass('table-fixed'); | ||
}); | ||
|
||
it('Renders columns with widths set by cols attribute', () => { | ||
const cols = ['20%', '30%', '50%']; | ||
render(TableWith3Cols, { cols }); | ||
|
||
for (const [i, width] of cols.entries()) { | ||
const col = screen.getByTestId(`col-${i}`); | ||
expect(col).toBeVisible(); | ||
expect(col).toHaveStyle(`width:${width}`); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!-- | ||
@component | ||
A table. | ||
```svelte | ||
<Table variant='fixed' cols=["30%", "30%", "40%"]> | ||
... | ||
</Table> | ||
``` | ||
--> | ||
<svelte:options immutable /> | ||
|
||
<script | ||
lang="ts" | ||
context="module" | ||
> | ||
export type TableVariant = 'auto' | 'fixed'; | ||
</script> | ||
|
||
<script lang="ts"> | ||
import cx from 'classnames'; | ||
/** Column width layout variant (optional) */ | ||
export let variant: TableVariant = 'auto'; | ||
/** | ||
* Column width sizes | ||
* @example | ||
* cols={["10%", "30%", "60%"]} | ||
*/ | ||
export let cols: string[] = []; | ||
/** | ||
* Custom table style | ||
* @example | ||
* style="border-collapse" | ||
*/ | ||
export let style = ''; | ||
</script> | ||
|
||
<table | ||
{style} | ||
class={cx('w-full bg-white text-xs', { | ||
'table-fixed': variant === 'fixed', | ||
'table-auto': variant === 'auto', | ||
})} | ||
> | ||
<colgroup> | ||
{#each cols as col, index} | ||
<col | ||
data-testid={`col-${index}`} | ||
style="width: {col};" | ||
/> | ||
{/each} | ||
</colgroup> | ||
<slot /> | ||
</table> | ||
|
||
<style> | ||
:host { | ||
display: contents !important; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!-- | ||
@component | ||
A table body. | ||
```svelte | ||
<Table> | ||
<TBody></TBody> | ||
</Table> | ||
``` | ||
--> | ||
<svelte:options immutable /> | ||
|
||
<script lang="ts"> | ||
/** | ||
* Custom table body style | ||
* @example | ||
* style="border-collapse" | ||
*/ | ||
export let style = ''; | ||
</script> | ||
|
||
<tbody {style}> | ||
<slot /> | ||
</tbody> | ||
|
||
<style> | ||
:host { | ||
display: contents !important; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!-- | ||
@component | ||
A table body. | ||
```svelte | ||
<Table> | ||
<TBody> | ||
<TD></TD> | ||
</TBody> | ||
</Table> | ||
``` | ||
--> | ||
<svelte:options immutable /> | ||
|
||
<script lang="ts"> | ||
/** | ||
* Custom table data cell style | ||
* @example | ||
* style="border-collapse" | ||
*/ | ||
export let style = ''; | ||
</script> | ||
|
||
<td | ||
{style} | ||
part="table-cell" | ||
class="overflow-hidden p-2" | ||
> | ||
<slot /> | ||
</td> | ||
|
||
<style> | ||
:host { | ||
display: contents !important; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!-- | ||
@component | ||
A table header cell. | ||
```svelte | ||
<Table> | ||
<THead> | ||
<TH></TH> | ||
</THead> | ||
</Table> | ||
``` | ||
--> | ||
<svelte:options immutable /> | ||
|
||
<script lang="ts"> | ||
/** | ||
* Custom table header cell style | ||
* @example | ||
* style="border-collapse" | ||
*/ | ||
export let style = ''; | ||
</script> | ||
|
||
<th | ||
{style} | ||
class="overflow-hidden p-2 font-normal text-default" | ||
> | ||
<slot /> | ||
</th> | ||
|
||
<style> | ||
:host { | ||
display: contents !important; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!-- | ||
@component | ||
A table header. | ||
```svelte | ||
<Table> | ||
<THead> | ||
</THead> | ||
</Table> | ||
``` | ||
--> | ||
<svelte:options immutable /> | ||
|
||
<script lang="ts"> | ||
/** | ||
* Custom table header style | ||
* @example | ||
* style="border-collapse" | ||
*/ | ||
export let style = ''; | ||
</script> | ||
|
||
<thead | ||
{style} | ||
class="border-b border-black" | ||
> | ||
<slot /> | ||
</thead> | ||
|
||
<style> | ||
:host { | ||
display: contents !important; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- | ||
@component | ||
This component allows us to render a TR with its slotted | ||
children, due to limitations with rendering slots using | ||
`@testing-library`. | ||
See: | ||
- https://sveltesociety.dev/recipes/testing-and-debugging/unit-testing-svelte-component | ||
- https://github.com/testing-library/svelte-testing-library/issues/48 | ||
--> | ||
<script lang="ts"> | ||
import TR from './tr.svelte'; | ||
import TD from './td.svelte'; | ||
</script> | ||
|
||
<TR> | ||
<TD>data</TD> | ||
</TR> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { render, screen } from '@testing-library/svelte'; | ||
import TR from './tr.svelte'; | ||
import TRWithTD from './tr.spec.svelte'; | ||
|
||
describe('TR', () => { | ||
it('Renders default variant', () => { | ||
render(TR); | ||
expect(screen.getByRole('row')).toBeVisible(); | ||
expect(screen.getByRole('row')).toHaveClass('border-b'); | ||
}); | ||
|
||
it('Renders success variant', () => { | ||
render(TR, { variant: 'success' }); | ||
expect(screen.getByRole('row')).toBeVisible(); | ||
expect(screen.getByRole('row')).toHaveClass( | ||
'text-green-700 bg-green-50 border-green-100' | ||
); | ||
}); | ||
|
||
it('Renders disabled variant', () => { | ||
render(TR, { variant: 'disabled' }); | ||
expect(screen.getByRole('row')).toBeVisible(); | ||
expect(screen.getByRole('row')).toHaveClass('text-gray-500 bg-gray-50'); | ||
}); | ||
|
||
it('Renders error variant', () => { | ||
render(TR, { variant: 'error' }); | ||
expect(screen.getByRole('row')).toBeVisible(); | ||
expect(screen.getByRole('row')).toHaveClass( | ||
'text-red-500 bg-red-50 border-red-100' | ||
); | ||
}); | ||
|
||
it('Renders table data', () => { | ||
render(TRWithTD); | ||
expect(screen.getByText('data')); | ||
}); | ||
}); |
Oops, something went wrong.