@@ -5,24 +5,7 @@ import LevelUpAltIcon from '@patternfly/react-icons/dist/esm/icons/level-up-alt-
55import * as tokensModule from '@patternfly/react-tokens/dist/esm/componentIndex'
66import React from 'react'
77import { CSSSearch } from './CSSSearch'
8-
9- export type ComponentProp = {
10- isOpen : boolean
11- cells : [
12- string ,
13- {
14- type : string
15- key : string
16- ref : any
17- props : any
18- } ,
19- ]
20- details : {
21- parent : number
22- fullWidth : boolean
23- data : any
24- }
25- }
8+ import { AutoLinkHeader } from './AutoLinkHeader'
269
2710type Value = {
2811 name : string
@@ -47,16 +30,17 @@ type List = {
4730}
4831
4932type FilteredRows = {
50- cells : ( React . ReactNode | string | string [ ] ) [ ]
33+ cells : React . ReactNode [ ]
5134 isOpen ?: boolean
5235 details ?: { parent : number ; fullWidth : boolean ; data : React . ReactNode }
5336}
5437
5538interface CSSTableProps extends React . HTMLProps < HTMLDivElement > {
5639 cssPrefix : string
57- headingLevel ?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
5840 hideSelectorColumn ?: boolean
5941 selector ?: string
42+ debounceLength ?: number
43+ autoLinkHeader ?: boolean
6044}
6145
6246const isColorRegex = / ^ ( # | r g b ) /
@@ -96,9 +80,10 @@ const flattenList = (files: FileList[]) => {
9680
9781export const CSSTable : React . FunctionComponent < CSSTableProps > = ( {
9882 cssPrefix,
99- headingLevel = 'h3' ,
10083 hideSelectorColumn = false ,
10184 selector,
85+ debounceLength = 500 ,
86+ autoLinkHeader,
10287} ) => {
10388 const prefixToken = cssPrefix . replace ( 'pf-v6-' , '' ) . replace ( / - + / g, '_' )
10489
@@ -182,9 +167,7 @@ export const CSSTable: React.FunctionComponent<CSSTableProps> = ({
182167 const [ searchRE , setSearchRE ] = useState < RegExp > ( INITIAL_REGEX )
183168 const [ rows , setRows ] = useState ( getFilteredRows ( searchRE ) )
184169
185- const SectionHeading = headingLevel
186- //const publicProps = componentProps?.filter((prop) => !prop.isHidden)
187- const hasPropsToRender = ! ( typeof cssPrefix === 'undefined' )
170+ const hasPrefixToRender = ! ( typeof cssPrefix === 'undefined' )
188171
189172 const onCollapse = (
190173 _event : React . MouseEvent ,
@@ -208,75 +191,78 @@ export const CSSTable: React.FunctionComponent<CSSTableProps> = ({
208191 const newSearchRE = new RegExp ( value , 'i' )
209192 setSearchRE ( newSearchRE )
210193 setRows ( getFilteredRows ( newSearchRE ) )
211- } , 500 )
194+ } , debounceLength )
212195
213196 return (
214- < div >
215- < SectionHeading > CSS variables</ SectionHeading >
216- < Stack hasGutter >
217- { hasPropsToRender && (
218- < >
219- < CSSSearch getDebouncedFilteredRows = { getDebouncedFilteredRows } />
220- < Table
221- variant = "compact"
222- aria-label = { `CSS Variables prefixed with ${ cssPrefix } ` }
223- >
224- < Thead >
225- < Tr >
226- { ! hideSelectorColumn && (
227- < React . Fragment >
228- < Th screenReaderText = "Expand or collapse column" />
229- < Th > Selector</ Th >
230- </ React . Fragment >
231- ) }
232- < Th > Variable</ Th >
233- < Th > Value</ Th >
234- </ Tr >
235- </ Thead >
236- { ! hideSelectorColumn ? (
237- rows . map ( ( row , rowIndex : number ) => (
238- < Tbody key = { rowIndex } isExpanded = { row . isOpen } >
239- < Tr >
240- < Td
241- expand = {
242- row . details
243- ? {
244- rowIndex,
245- isExpanded : row . isOpen || false ,
246- onToggle : onCollapse ,
247- expandId : `css-vars-expandable-toggle-${ cssPrefix } ` ,
248- }
249- : undefined
250- }
251- />
252- < Td dataLabel = "Selector" > { row . cells [ 0 ] } </ Td >
253- < Td dataLabel = "Variable" > { row . cells [ 1 ] } </ Td >
254- < Td dataLabel = "Value" > { row . cells [ 2 ] } </ Td >
255- </ Tr >
256- { row . details ? (
257- < Tr isExpanded = { row . isOpen } >
258- { ! row . details . fullWidth ? < Td /> : null }
259- < Td dataLabel = "Selector" colSpan = { 5 } >
260- { row . details . data }
261- </ Td >
262- </ Tr >
263- ) : null }
264- </ Tbody >
265- ) )
266- ) : (
267- < Tbody >
268- { rows . map ( ( row , rowIndex : number ) => (
269- < Tr key = { rowIndex } >
270- < Td dataLabel = "Variable" > { row . cells [ 0 ] } </ Td >
271- < Td dataLabel = "Value" > { row . cells [ 1 ] } </ Td >
197+ < Stack hasGutter >
198+ { hasPrefixToRender && (
199+ < >
200+ { autoLinkHeader && (
201+ < AutoLinkHeader
202+ headingLevel = "h3"
203+ className = "pf-v6-u-mt-lg pf-v6-u-mb-md"
204+ > { `Prefixed with '${ cssPrefix } '` } </ AutoLinkHeader >
205+ ) }
206+ < CSSSearch getDebouncedFilteredRows = { getDebouncedFilteredRows } />
207+ < Table
208+ variant = "compact"
209+ aria-label = { `CSS Variables prefixed with ${ cssPrefix } ` }
210+ >
211+ < Thead >
212+ < Tr >
213+ { ! hideSelectorColumn && (
214+ < React . Fragment >
215+ < Th screenReaderText = "Expand or collapse column" />
216+ < Th > Selector</ Th >
217+ </ React . Fragment >
218+ ) }
219+ < Th > Variable</ Th >
220+ < Th > Value</ Th >
221+ </ Tr >
222+ </ Thead >
223+ { ! hideSelectorColumn ? (
224+ rows . map ( ( row , rowIndex : number ) => (
225+ < Tbody key = { rowIndex } isExpanded = { row . isOpen } >
226+ < Tr >
227+ < Td
228+ expand = {
229+ row . details
230+ ? {
231+ rowIndex,
232+ isExpanded : row . isOpen || false ,
233+ onToggle : onCollapse ,
234+ expandId : `css-vars-expandable-toggle-${ cssPrefix } ` ,
235+ }
236+ : undefined
237+ }
238+ />
239+ < Td dataLabel = "Selector" > { row . cells [ 0 ] } </ Td >
240+ < Td dataLabel = "Variable" > { row . cells [ 1 ] } </ Td >
241+ < Td dataLabel = "Value" > { row . cells [ 2 ] } </ Td >
242+ </ Tr >
243+ { row . details ? (
244+ < Tr isExpanded = { row . isOpen } >
245+ { ! row . details . fullWidth ? < Td /> : null }
246+ < Td dataLabel = "Selector" colSpan = { 5 } >
247+ { row . details . data }
248+ </ Td >
272249 </ Tr >
273- ) ) }
250+ ) : null }
274251 </ Tbody >
275- ) }
276- </ Table >
277- </ >
278- ) }
279- </ Stack >
280- </ div >
252+ ) )
253+ ) : (
254+ < Tbody >
255+ { rows . map ( ( row , rowIndex : number ) => (
256+ < Tr key = { rowIndex } >
257+ < Td dataLabel = "Variable" > { row . cells [ 0 ] } </ Td >
258+ < Td dataLabel = "Value" > { row . cells [ 1 ] } </ Td >
259+ </ Tr >
260+ ) ) }
261+ </ Tbody >
262+ ) }
263+ </ Table >
264+ </ >
265+ ) }
266+ </ Stack >
281267 )
282268}
0 commit comments