Skip to content

Commit e93f276

Browse files
committed
✨ Add support for scrollable tables
1 parent be43fe9 commit e93f276

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed

src/components/Table/Table.astro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
striped,
1313
offsetStripe,
1414
compact,
15+
maxHeight,
1516
className
1617
} = Astro.props
1718
@@ -21,11 +22,15 @@ const classes = [
2122
striped && styles[`striped-${striped}s`],
2223
offsetStripe && styles.offset,
2324
compact && styles.compact,
25+
maxHeight && styles.scroll,
2426
className
2527
]
2628
---
2729

28-
<div class:list={classes}>
30+
<div
31+
class:list={classes}
32+
style={maxHeight ? `max-height:${maxHeight}` : undefined}
33+
>
2934
<table>
3035
{headings?.length && (
3136
<thead>

src/components/Table/Table.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
export let striped: TableProps['striped'] = null
1212
export let offsetStripe: TableProps['offsetStripe'] = false
1313
export let compact: TableProps['compact'] = false
14+
export let maxHeight: TableProps['maxHeight'] = 0
1415
export let className: TableProps['className'] = ''
1516
1617
const classes = classNames([
@@ -19,11 +20,12 @@
1920
striped && styles[`striped-${striped}s`],
2021
offsetStripe && styles.offset,
2122
compact && styles.compact,
23+
maxHeight && styles.scroll,
2224
className
2325
])
2426
</script>
2527

26-
<div class={classes}>
28+
<div class={classes} style={maxHeight ? `max-height:${maxHeight}` : null}>
2729
<table>
2830
{#if headings?.length}
2931
<thead>

src/components/Table/Table.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Table = ({
1212
striped,
1313
offsetStripe,
1414
compact,
15+
maxHeight,
1516
className
1617
}: TableProps) => {
1718
const classes = classNames([
@@ -20,11 +21,16 @@ const Table = ({
2021
striped && styles[`striped-${striped}s`],
2122
offsetStripe && styles.offset,
2223
compact && styles.compact,
24+
maxHeight && styles.scroll,
2325
className
2426
])
2527

28+
const styleVariables = {
29+
...(maxHeight && { 'max-height': maxHeight })
30+
} as React.CSSProperties
31+
2632
return (
27-
<div className={classes}>
33+
<div className={classes} style={styleVariables}>
2834
<table>
2935
{headings?.length && (
3036
<thead>

src/components/Table/table.module.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,14 @@
5757
@include spacing(py-xxs, px-sm);
5858
}
5959
}
60+
61+
&.scroll {
62+
@include spacing(pr-sm);
63+
64+
thead {
65+
@include position(sticky, t0);
66+
@include background(primary-70);
67+
box-shadow: 0 .5px 0 var(--w-color-primary-50);
68+
}
69+
}
6070
}

src/components/Table/table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export type TableProps = {
66
striped?: 'column' | 'row' | null
77
offsetStripe?: boolean
88
compact?: boolean
9+
maxHeight?: number
910
className?: string
1011
}

src/pages/table.astro

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ const overflowTable = {
4646
''
4747
]),
4848
}
49+
50+
const scrollTable = {
51+
headings: ['Keyword', 'CSS'],
52+
data: [
53+
['none', '0'],
54+
['xxs', '2px'],
55+
['xs', '5px'],
56+
['sm', '10px'],
57+
['md', '15px'],
58+
['default', '20px'],
59+
['lg', '25px'],
60+
['xl', '30px'],
61+
['2xl', '35px'],
62+
['3xl', '40px'],
63+
['4xl', '45px'],
64+
['5xl', '50px'],
65+
['6xl', '55px'],
66+
['7xl', '60px'],
67+
['8xl', '65px'],
68+
['9xl', '70px'],
69+
['10xl', '75px']
70+
]
71+
}
4972
---
5073

5174
<Layout>
@@ -148,6 +171,14 @@ const overflowTable = {
148171
striped="column"
149172
/>
150173
</ComponentWrapper>
174+
175+
<ComponentWrapper title="Scroll table">
176+
<section.component
177+
{...scrollTable}
178+
maxHeight="250px"
179+
striped="column"
180+
/>
181+
</ComponentWrapper>
151182
</div>
152183
))}
153184
</Layout>

0 commit comments

Comments
 (0)