Skip to content

Commit

Permalink
fix: checkbox and expandable row max width
Browse files Browse the repository at this point in the history
  • Loading branch information
matthprost committed Dec 16, 2024
1 parent 27dfa74 commit 9d7eed1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
11 changes: 5 additions & 6 deletions packages/ui/src/components/List/HeaderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import { useTheme } from '@emotion/react'
import styled from '@emotion/styled'
import type { ReactNode } from 'react'
import { Checkbox } from '../Checkbox'
import {
EXPANDABLE_COLUMN_SIZE,
SELECTABLE_CHECKBOX_SIZE,
} from '../Table/constants'
import { HeaderCell } from './HeaderCell'
import { useListContext } from './ListContext'
import { EXPANDABLE_COLUMN_SIZE, SELECTABLE_CHECKBOX_SIZE } from './constants'

const StyledHeaderRow = styled.tr`
/* List itself also apply style about common templating between HeaderRow and other Rows */
Expand Down Expand Up @@ -61,7 +58,9 @@ export const HeaderRow = ({ children, hasSelectAllColumn }: RowProps) => {
<thead>
<StyledHeaderRow>
{hasSelectAllColumn ? (
<NoPaddingHeaderCell width={theme.sizing[SELECTABLE_CHECKBOX_SIZE]}>
<NoPaddingHeaderCell
maxWidth={theme.sizing[SELECTABLE_CHECKBOX_SIZE]}
>
<Checkbox
name="list-select-checkbox"
value="all"
Expand All @@ -73,7 +72,7 @@ export const HeaderRow = ({ children, hasSelectAllColumn }: RowProps) => {
</NoPaddingHeaderCell>
) : null}
{expandButton ? (
<NoPaddingHeaderCell width={theme.sizing[EXPANDABLE_COLUMN_SIZE]}>
<NoPaddingHeaderCell maxWidth={theme.sizing[EXPANDABLE_COLUMN_SIZE]}>

Check warning on line 75 in packages/ui/src/components/List/HeaderRow.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/List/HeaderRow.tsx#L75

Added line #L75 was not covered by tests
{null}
</NoPaddingHeaderCell>
) : null}
Expand Down
19 changes: 16 additions & 3 deletions packages/ui/src/components/List/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useTheme } from '@emotion/react'
import styled from '@emotion/styled'
import type { ForwardedRef, ReactNode } from 'react'
import {
Expand All @@ -14,6 +15,7 @@ import { Checkbox } from '../Checkbox'
import { Tooltip } from '../Tooltip'
import { Cell } from './Cell'
import { useListContext } from './ListContext'
import { SELECTABLE_CHECKBOX_SIZE } from './constants'
import type { ColumnProps } from './types'

const ExpandableWrapper = styled.tr`
Expand Down Expand Up @@ -151,12 +153,18 @@ const StyledCheckboxContainer = styled.div`
display: flex;
`

const NoPaddingCell = styled(Cell)`
const NoPaddingCell = styled(Cell, {
shouldForwardProp: prop => !['maxWidth'].includes(prop),
})<{
maxWidth: string
}>`
padding: 0;
&:first-of-type {
padding-left: ${({ theme }) => theme.space['2']};
}
max-width: ${({ maxWidth }) => maxWidth};
`

const ExpandableCell = styled(Cell, {
Expand Down Expand Up @@ -216,6 +224,8 @@ export const Row = forwardRef(
columns,
} = useListContext()

const theme = useTheme()

const expandedRowId = useId()

const checkboxRef = useRef<HTMLInputElement>(null)
Expand Down Expand Up @@ -296,7 +306,10 @@ export const Row = forwardRef(
columnsStartAt={(selectable ? 1 : 0) + (expandButton ? 1 : 0)}
>
{selectable ? (
<NoPaddingCell preventClick={canClickRowToExpand}>
<NoPaddingCell
preventClick={canClickRowToExpand}
maxWidth={theme.sizing[SELECTABLE_CHECKBOX_SIZE]}
>
<StyledCheckboxContainer>
<Tooltip
text={
Expand Down Expand Up @@ -326,7 +339,7 @@ export const Row = forwardRef(
</NoPaddingCell>
) : null}
{expandButton ? (
<NoPaddingCell>
<NoPaddingCell maxWidth={theme.sizing[SELECTABLE_CHECKBOX_SIZE]}>

Check warning on line 342 in packages/ui/src/components/List/Row.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/List/Row.tsx#L342

Added line #L342 was not covered by tests
<Button
disabled={disabled || !expandable}
icon={expandedRowIds[id] ? 'arrow-up' : 'arrow-down'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6852,7 +6852,7 @@ exports[`List > Should render correctly with loading with selectable 1`] = `
color: #3f4250;
gap: 0.5rem;
padding: 0 1rem;
width: 2.5rem;
max-width: 2.5rem;
padding: 0;
}
Expand Down Expand Up @@ -9175,7 +9175,7 @@ exports[`List > Should render correctly with selectable 1`] = `
color: #3f4250;
gap: 0.5rem;
padding: 0 1rem;
width: 2.5rem;
max-width: 2.5rem;
padding: 0;
}
Expand Down Expand Up @@ -9588,6 +9588,7 @@ exports[`List > Should render correctly with selectable 1`] = `
height: 3.75rem;
padding: 0 1rem;
padding: 0;
max-width: 2.5rem;
}
.emotion-46:first-of-type {
Expand Down Expand Up @@ -10859,7 +10860,7 @@ exports[`List > Should render correctly with selectable then click on first row
color: #3f4250;
gap: 0.5rem;
padding: 0 1rem;
width: 2.5rem;
max-width: 2.5rem;
padding: 0;
}
Expand Down Expand Up @@ -10889,7 +10890,7 @@ exports[`List > Should render correctly with selectable then click on first row
color: #3f4250;
gap: 0.5rem;
padding: 0 1rem;
width: 2.5rem;
max-width: 2.5rem;
padding: 0;
}
Expand Down Expand Up @@ -11689,6 +11690,7 @@ exports[`List > Should render correctly with selectable then click on first row
height: 3.75rem;
padding: 0 1rem;
padding: 0;
max-width: 2.5rem;
}
.emotion-46:first-of-type {
Expand All @@ -11701,6 +11703,7 @@ exports[`List > Should render correctly with selectable then click on first row
height: 3.75rem;
padding: 0 1rem;
padding: 0;
max-width: 2.5rem;
}
.emotion-46:first-of-type {
Expand Down Expand Up @@ -13124,7 +13127,7 @@ exports[`List > Should render correctly with selectable with shift click for mul
color: #3f4250;
gap: 0.5rem;
padding: 0 1rem;
width: 2.5rem;
max-width: 2.5rem;
padding: 0;
}
Expand Down Expand Up @@ -13154,7 +13157,7 @@ exports[`List > Should render correctly with selectable with shift click for mul
color: #3f4250;
gap: 0.5rem;
padding: 0 1rem;
width: 2.5rem;
max-width: 2.5rem;
padding: 0;
}
Expand Down Expand Up @@ -13954,6 +13957,7 @@ exports[`List > Should render correctly with selectable with shift click for mul
height: 3.75rem;
padding: 0 1rem;
padding: 0;
max-width: 2.5rem;
}
.emotion-48:first-of-type {
Expand All @@ -13966,6 +13970,7 @@ exports[`List > Should render correctly with selectable with shift click for mul
height: 3.75rem;
padding: 0 1rem;
padding: 0;
max-width: 2.5rem;
}
.emotion-48:first-of-type {
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/List/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const SELECTABLE_CHECKBOX_SIZE = 24
export const EXPANDABLE_COLUMN_SIZE = 32
export const SELECTABLE_CHECKBOX_SIZE = '500' // sizing token from theme
export const EXPANDABLE_COLUMN_SIZE = '500'

0 comments on commit 9d7eed1

Please sign in to comment.