|
5 | 5 | * found at http://www.apache.org/licenses/LICENSE-2.0. |
6 | 6 | */ |
7 | 7 |
|
8 | | -import styled from 'styled-components'; |
9 | | -import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming'; |
| 8 | +import styled, { css, DefaultTheme, ThemeProps } from 'styled-components'; |
| 9 | +import { retrieveComponentStyles, DEFAULT_THEME, getColor } from '@zendeskgarden/react-theming'; |
| 10 | +import { StyledHeaderRow } from './StyledHeaderRow'; |
10 | 11 |
|
11 | 12 | const COMPONENT_ID = 'tables.head'; |
12 | 13 |
|
| 14 | +interface IStyledHeadProps { |
| 15 | + isSticky?: boolean; |
| 16 | +} |
| 17 | + |
| 18 | +/* |
| 19 | + * 1. Prevent <Checkbox> or <OverflowButton> from leaking over the sticky header |
| 20 | + * 2. Replace header row border with a box-shadow that maintains position |
| 21 | + */ |
| 22 | +const stickyStyles = (props: ThemeProps<DefaultTheme>) => { |
| 23 | + const borderColor = getColor('neutralHue', 300, props.theme); |
| 24 | + |
| 25 | + return css` |
| 26 | + position: sticky; |
| 27 | + top: 0; |
| 28 | + z-index: 1; /* [1] */ |
| 29 | + box-shadow: inset 0 -${props.theme.borderWidths.sm} 0 ${borderColor}; /* [2] */ |
| 30 | + background-color: ${props.theme.colors.background}; |
| 31 | +
|
| 32 | + & > ${StyledHeaderRow}:last-child { |
| 33 | + border-bottom-color: transparent; /* [2] */ |
| 34 | + } |
| 35 | + `; |
| 36 | +}; |
| 37 | + |
13 | 38 | export const StyledHead = styled.thead.attrs({ |
14 | 39 | 'data-garden-id': COMPONENT_ID, |
15 | 40 | 'data-garden-version': PACKAGE_VERSION |
16 | | -})` |
| 41 | +})<IStyledHeadProps>` |
| 42 | + ${props => props.isSticky && stickyStyles(props)} |
| 43 | +
|
17 | 44 | ${props => retrieveComponentStyles(COMPONENT_ID, props)}; |
18 | 45 | `; |
19 | 46 |
|
|
0 commit comments