Skip to content

Commit

Permalink
chore(Table): docs and housekeeping (#1722)
Browse files Browse the repository at this point in the history
I see that we need some refactoring, while working on another larger PR.
  • Loading branch information
tujoworker authored Nov 15, 2022
1 parent 4d3e800 commit 6c36c1f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ Tables do both serve as a way of navigation for screen readers and other asserti

Use the documentation from [MDN – The Table element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) for more information on making semantic correct tables, including `scope`, `align`, `colSpan` and `rowSpan`.

Here is a list of things you may follow along in order to ensure your coded tables still are accessible:

- Keep a semantic correct structure.
- Let tables align the column width, when possible.
- Do not use CSS `display` property on any table element.
- Do not overwrite styles in general, but rather get in touch with DNB UX.

## Table header components

- `<Th.SortButton />` to be used for additional sorting functionality.
Expand Down
10 changes: 9 additions & 1 deletion packages/dnb-eufemia/src/components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ const Table = (
return (
<Provider skeleton={Boolean(skeleton)}>
<TableContext.Provider
value={{ trCountRef, rerenderAlias, forceRerender }}
value={{
trCountRef,
rerenderAlias,
forceRerender,
allProps: {
...context.getTranslation(componentProps).Table,
...allProps,
},
}}
>
<table
className={classnames(
Expand Down
13 changes: 3 additions & 10 deletions packages/dnb-eufemia/src/components/table/TableTd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ export type TableTdProps = {
children?: React.ReactNode
}

const Td = (
export default function Td(
componentProps: TableTdProps &
React.TdHTMLAttributes<HTMLTableCellElement>
) => {
const {
className,
children,

...props
} = componentProps
) {
const { className, children, ...props } = componentProps

return (
<td
Expand All @@ -30,5 +25,3 @@ const Td = (
</td>
)
}

export default Td
40 changes: 12 additions & 28 deletions packages/dnb-eufemia/src/components/table/TableTr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,34 @@ export type TableTrProps = {
| Array<React.ReactElement<TableTdProps>>
}

const Tr = (
export default function Tr(
componentProps: TableTrProps &
React.TableHTMLAttributes<HTMLTableRowElement>
) => {
) {
const {
variant,
className,
children,

className: _className,
...props
} = componentProps

const tableContext = React.useContext(TableContext)
const { currentVariant } = useHandleTrVariant({ variant })

const { currentVariant, trRef, trParams } = useHandleTrLogic({
tableContext,
variant,
})
const className = classnames(
'dnb-table__tr',
currentVariant && `dnb-table__tr--${currentVariant}`,
_className
)

return (
<tr
role="row"
className={classnames(
'dnb-table__tr',
currentVariant && `dnb-table__tr--${currentVariant}`,
className
)}
ref={trRef}
{...trParams}
{...props}
>
<tr role="row" className={className} {...props}>
{children}
</tr>
)
}

export default Tr

function useHandleTrLogic({ tableContext, variant }) {
const trRef = React.useRef(null)
function useHandleTrVariant({ variant }) {
const tableContext = React.useContext(TableContext)

/**
* Handle odd/even
Expand Down Expand Up @@ -112,11 +100,7 @@ function useHandleTrLogic({ tableContext, variant }) {
currentVariant = count % 2 ? 'odd' : 'even'
}

const trParams = {}

return {
trRef,
currentVariant,
trParams,
}
}

0 comments on commit 6c36c1f

Please sign in to comment.