Skip to content

Commit e4def1f

Browse files
Merge pull request #54 from rebeccaalpert/css-table
feat(CSSTable): Add CSS variable table
2 parents bbf7493 + d2cafc6 commit e4def1f

File tree

16 files changed

+687
-36
lines changed

16 files changed

+687
-36
lines changed

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const config: Config = {
2020
},
2121
setupFilesAfterEnv: ['<rootDir>/test.setup.ts'],
2222
transformIgnorePatterns: [
23-
'/node_modules/(?!(change-case|@?nanostores|react-docgen|strip-indent)/)',
23+
'/node_modules/(?!(change-case|@?nanostores|react-docgen|strip-indent|@patternfly/react-icons)/)',
2424
],
2525
}
2626

src/components/AutoLinkHeader.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Flex, FlexItem, Content, Button } from '@patternfly/react-core'
2+
import LinkIcon from '@patternfly/react-icons/dist/esm/icons/link-icon'
3+
import { slugger } from '../utils/slugger'
4+
import { css } from '@patternfly/react-styles'
5+
6+
interface AutoLinkHeaderProps extends React.HTMLProps<HTMLDivElement> {
7+
id?: string
8+
headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
9+
children: React.ReactNode
10+
metaText?: React.ReactNode
11+
className?: string
12+
}
13+
14+
export const AutoLinkHeader = ({
15+
id,
16+
headingLevel,
17+
children,
18+
metaText,
19+
className,
20+
}: AutoLinkHeaderProps) => {
21+
const slug = id || slugger(children)
22+
23+
return (
24+
<Flex
25+
alignItems={{ default: 'alignItemsCenter' }}
26+
spaceItems={{ default: 'spaceItemsSm' }}
27+
>
28+
<FlexItem>
29+
<Content
30+
id={slug}
31+
component={headingLevel}
32+
className={css('ws-heading', className)}
33+
tabIndex={-1}
34+
isEditorial
35+
>
36+
<Button
37+
href={`#${slug}`}
38+
component="a"
39+
className="ws-heading-anchor"
40+
tabIndex={-1}
41+
aria-hidden
42+
variant="plain"
43+
isInline
44+
>
45+
<LinkIcon
46+
className="ws-heading-anchor-icon"
47+
style={{ verticalAlign: 'middle' }}
48+
/>
49+
</Button>
50+
{children}
51+
</Content>
52+
</FlexItem>
53+
{metaText && <FlexItem>{metaText}</FlexItem>}
54+
</Flex>
55+
)
56+
}

src/components/CSSSearch.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useState } from 'react'
2+
import { SearchInput } from '@patternfly/react-core'
3+
4+
interface CSSSearchProps {
5+
getDebouncedFilteredRows: (value: string) => void
6+
'aria-label'?: string
7+
placeholder?: string
8+
}
9+
10+
export const CSSSearch: React.FC<CSSSearchProps> = ({
11+
getDebouncedFilteredRows,
12+
'aria-label': ariaLabel = 'Filter CSS Variables',
13+
placeholder = 'Filter CSS Variables',
14+
}: CSSSearchProps) => {
15+
const [filterValue, setFilterValue] = useState('')
16+
17+
const onFilterChange = (
18+
_event: React.FormEvent<HTMLInputElement>,
19+
value: string,
20+
) => {
21+
setFilterValue(value)
22+
getDebouncedFilteredRows(value)
23+
}
24+
25+
return (
26+
<SearchInput
27+
aria-label={ariaLabel}
28+
placeholder={placeholder}
29+
value={filterValue}
30+
onChange={onFilterChange}
31+
/>
32+
)
33+
}

src/components/CSSTable.astro

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
import { CSSTable as CSSTableComponent } from './CSSTable'
3+
import { AutoLinkHeader } from './AutoLinkHeader'
4+
import { Stack, StackItem } from '@patternfly/react-core'
5+
6+
const { cssPrefix } = Astro.props
7+
---
8+
9+
{
10+
cssPrefix?.length > 0 && (
11+
<Stack hasGutter>
12+
<StackItem>
13+
<AutoLinkHeader
14+
headingLevel="h2"
15+
className="pf-v6-c-content--h2"
16+
id="css-variables"
17+
>
18+
CSS variables
19+
</AutoLinkHeader>
20+
</StackItem>
21+
22+
{cssPrefix.map((prefix: string, index: number) => (
23+
<StackItem key={index}>
24+
<CSSTableComponent
25+
autoLinkHeader={cssPrefix.length > 1}
26+
cssPrefix={prefix}
27+
client:only="react"
28+
/>
29+
</StackItem>
30+
))}
31+
</Stack>
32+
)
33+
}

0 commit comments

Comments
 (0)