11'use client'
22
3- import styled from '@emotion/styled'
43import {
54 InformationOutlineIcon ,
65 SortIcon as SortIconUV ,
76 SouthShortIcon ,
87} from '@ultraviolet/icons'
8+ import { assignInlineVars } from '@vanilla-extract/dynamic'
99import type { ReactNode } from 'react'
10+ import { listSortIcon } from '../List/styles.css'
1011import { Text } from '../Text'
1112import { Tooltip } from '../Tooltip'
12-
13- const StyledSortIcon = styled ( SouthShortIcon , {
14- shouldForwardProp : prop => ! [ 'order' ] . includes ( prop ) ,
15- } ) < { order : 'ascending' | 'descending' } > `
16- transform: ${ ( { order } ) =>
17- order === 'ascending' ? 'rotate(-180deg)' : 'none' } ;
18- transition: transform 0.2s;
19- `
13+ import { headerCellText , tableHeaderCell } from './styles.css'
14+ import {
15+ headerCellMaxWidth ,
16+ headerCellMinWidth ,
17+ headerCellWidth ,
18+ } from './variables.css'
2019
2120const SortIcon = ( { order } : { order ?: 'ascending' | 'descending' } ) =>
2221 order ? (
23- < StyledSortIcon order = { order } sentiment = "primary" />
22+ < SouthShortIcon className = { listSortIcon [ order ] } sentiment = "primary" />
2423 ) : (
2524 < SortIconUV sentiment = "neutral" />
2625 )
2726
28- type StyledHeaderCellProps = Pick <
29- HeaderCellProps ,
30- 'width' | 'maxWidth' | 'minWidth'
31- > & {
32- align ?: 'left' | 'center' | 'right'
33- }
34-
35- const StyledHeaderCell = styled ( 'th' , {
36- shouldForwardProp : prop =>
37- ! [ 'align' , 'width' , 'maxWidth' , 'minWidth' ] . includes ( prop ) ,
38- } ) < StyledHeaderCellProps > `
39- ${ ( { width, maxWidth, minWidth } ) => `
40- ${ width ? `width: ${ width } ;` : '' }
41- ${ maxWidth ? `max-width: ${ maxWidth } ;` : '' }
42- ${ minWidth ? `min-width: ${ minWidth } ;` : '' }
43- ` }
44- display: table-cell;
45- vertical-align: middle;
46- text-align: ${ ( { align } ) => align } ;
47- padding: ${ ( { theme } ) => theme . space [ '1' ] } ;
48-
49- &[role*='button'] {
50- cursor: pointer;
51- user-select: none;
52- }
53-
54- &:first-of-type {
55- &[data-checkbox="true"] {
56- padding-left: ${ ( { theme } ) => theme . space [ '2' ] } ;
57- }
58- }
59- `
60-
61- const StyledText = styled ( Text ) `
62- display: flex;
63- flex-direction: row;
64- align-items: center;
65- gap: ${ ( { theme } ) => theme . space [ '1' ] } ;
66- `
67-
6827type HeaderCellProps = {
6928 children : ReactNode
7029 className ?: string
@@ -104,13 +63,10 @@ export const HeaderCell = ({
10463 : undefined
10564
10665 return (
107- < StyledHeaderCell
66+ < th
10867 align = { align }
10968 aria-sort = { order }
110- className = { className }
111- data-checkbox = { isCheckbox }
112- maxWidth = { maxWidth }
113- minWidth = { minWidth }
69+ className = { `${ className ? `${ className } ` : '' } ${ tableHeaderCell ( { align, checked : isCheckbox } ) } ` }
11470 onClick = { handleOrder }
11571 onKeyDown = {
11672 handleOrder
@@ -126,11 +82,16 @@ export const HeaderCell = ({
12682 : undefined
12783 }
12884 role = { onOrder ? 'button columnheader' : undefined }
85+ style = { assignInlineVars ( {
86+ [ headerCellWidth ] : width ?? 'auto' ,
87+ [ headerCellMaxWidth ] : maxWidth ?? 'none' ,
88+ [ headerCellMinWidth ] : minWidth ?? 'auto' ,
89+ } ) }
12990 tabIndex = { handleOrder ? 0 : - 1 }
130- width = { width }
13191 >
132- < StyledText
92+ < Text
13393 as = "div"
94+ className = { headerCellText }
13495 sentiment = { order !== undefined ? 'primary' : 'neutral' }
13596 variant = "bodySmall"
13697 >
@@ -147,7 +108,7 @@ export const HeaderCell = ({
147108 { orderDirection !== undefined && isOrdered !== undefined ? (
148109 < SortIcon aria-disabled = { ! onOrder } order = { order } />
149110 ) : null }
150- </ StyledText >
151- </ StyledHeaderCell >
111+ </ Text >
112+ </ th >
152113 )
153114}
0 commit comments