@patternfly/react-core 4.190.0 → 4.191.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.190.0",
3
+ "version": "4.191.3",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -34,9 +34,9 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.41.0",
38
- "@patternfly/react-styles": "^4.40.0",
39
- "@patternfly/react-tokens": "^4.42.0",
37
+ "@patternfly/react-icons": "^4.42.3",
38
+ "@patternfly/react-styles": "^4.41.3",
39
+ "@patternfly/react-tokens": "^4.43.3",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "e76b0322ba29c50bd1c4c86d4a24b2e032586e5a"
63
+ "gitHead": "f161ca861cb4f1a679ea090a0606c15bdd5e795b"
64
64
  }
@@ -4,6 +4,7 @@ import { css } from '@patternfly/react-styles';
4
4
  import MinusIcon from '@patternfly/react-icons/dist/esm/icons/minus-icon';
5
5
  import PlusIcon from '@patternfly/react-icons/dist/esm/icons/plus-icon';
6
6
  import { Button, ButtonProps } from '../Button';
7
+ import { KEY_CODES } from '../../helpers';
7
8
 
8
9
  export interface NumberInputProps extends React.HTMLProps<HTMLDivElement> {
9
10
  /** Value of the number input */
@@ -44,6 +45,19 @@ export interface NumberInputProps extends React.HTMLProps<HTMLDivElement> {
44
45
  plusBtnProps?: ButtonProps;
45
46
  }
46
47
 
48
+ type DefaultKeyDownHandlerArgs = Pick<NumberInputProps, 'inputName' | 'onMinus' | 'onPlus'>;
49
+
50
+ const defaultKeyDownHandler = (args: DefaultKeyDownHandlerArgs) => (event: React.KeyboardEvent<HTMLInputElement>) => {
51
+ if (KEY_CODES.ARROW_UP === event.keyCode && args.onPlus) {
52
+ event.preventDefault();
53
+ args.onPlus(null, args.inputName);
54
+ }
55
+ if (KEY_CODES.ARROW_DOWN === event.keyCode && args.onMinus) {
56
+ event.preventDefault();
57
+ args.onMinus(null, args.inputName);
58
+ }
59
+ };
60
+
47
61
  export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
48
62
  value = 0,
49
63
  className,
@@ -66,6 +80,8 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
66
80
  ...props
67
81
  }: NumberInputProps) => {
68
82
  const numberInputUnit = <div className={css(styles.numberInputUnit)}>{unit}</div>;
83
+ const keyDownHandler =
84
+ inputProps && inputProps.onKeyDown ? inputProps.onKeyDown : defaultKeyDownHandler({ inputName, onMinus, onPlus });
69
85
  return (
70
86
  <div
71
87
  className={css(styles.numberInput, className)}
@@ -100,6 +116,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
100
116
  {...(onChange && { onChange })}
101
117
  {...(!onChange && { readOnly: true })}
102
118
  {...inputProps}
119
+ onKeyDown={keyDownHandler}
103
120
  />
104
121
  <Button
105
122
  variant="control"
@@ -72,6 +72,7 @@ exports[`numberInput disables lower threshold 1`] = `
72
72
  <input
73
73
  aria-label="Input"
74
74
  className="pf-c-form-control"
75
+ onKeyDown={[Function]}
75
76
  readOnly={true}
76
77
  type="number"
77
78
  value={0}
@@ -209,6 +210,7 @@ exports[`numberInput disables upper threshold 1`] = `
209
210
  <input
210
211
  aria-label="Input"
211
212
  className="pf-c-form-control"
213
+ onKeyDown={[Function]}
212
214
  readOnly={true}
213
215
  type="number"
214
216
  value={100}
@@ -361,6 +363,7 @@ exports[`numberInput passes button props successfully 1`] = `
361
363
  <input
362
364
  aria-label="Input"
363
365
  className="pf-c-form-control"
366
+ onKeyDown={[Function]}
364
367
  readOnly={true}
365
368
  type="number"
366
369
  value={5}
@@ -504,6 +507,7 @@ exports[`numberInput passes input props successfully 1`] = `
504
507
  className="pf-c-form-control"
505
508
  name="test-name"
506
509
  onChange={[MockFunction]}
510
+ onKeyDown={[Function]}
507
511
  type="number"
508
512
  value={5}
509
513
  />
@@ -645,6 +649,7 @@ exports[`numberInput renders custom width 1`] = `
645
649
  <input
646
650
  aria-label="Input"
647
651
  className="pf-c-form-control"
652
+ onKeyDown={[Function]}
648
653
  readOnly={true}
649
654
  type="number"
650
655
  value={5}
@@ -783,6 +788,7 @@ exports[`numberInput renders defaults & extra props 1`] = `
783
788
  <input
784
789
  aria-label="Input"
785
790
  className="pf-c-form-control"
791
+ onKeyDown={[Function]}
786
792
  readOnly={true}
787
793
  type="number"
788
794
  value={0}
@@ -922,6 +928,7 @@ exports[`numberInput renders disabled 1`] = `
922
928
  aria-label="Input"
923
929
  className="pf-c-form-control"
924
930
  disabled={true}
931
+ onKeyDown={[Function]}
925
932
  readOnly={true}
926
933
  type="number"
927
934
  value={90}
@@ -1066,6 +1073,7 @@ exports[`numberInput renders unit & position 1`] = `
1066
1073
  <input
1067
1074
  aria-label="Input"
1068
1075
  className="pf-c-form-control"
1076
+ onKeyDown={[Function]}
1069
1077
  readOnly={true}
1070
1078
  type="number"
1071
1079
  value={5}
@@ -1204,6 +1212,7 @@ exports[`numberInput renders unit 1`] = `
1204
1212
  <input
1205
1213
  aria-label="Input"
1206
1214
  className="pf-c-form-control"
1215
+ onKeyDown={[Function]}
1207
1216
  readOnly={true}
1208
1217
  type="number"
1209
1218
  value={5}
@@ -1345,6 +1354,7 @@ exports[`numberInput renders value 1`] = `
1345
1354
  <input
1346
1355
  aria-label="Input"
1347
1356
  className="pf-c-form-control"
1357
+ onKeyDown={[Function]}
1348
1358
  readOnly={true}
1349
1359
  type="number"
1350
1360
  value={90}
@@ -357,3 +357,46 @@ class NumberInputSizes extends React.Component {
357
357
  }
358
358
  }
359
359
  ```
360
+
361
+ ### Custom increment/decrement
362
+
363
+ ```js
364
+ import React from 'react';
365
+ import { NumberInput } from '@patternfly/react-core';
366
+
367
+ class CustomStepNumberInput extends React.Component {
368
+ constructor(props) {
369
+ super(props);
370
+ this.state = {
371
+ value: 90,
372
+ step: 3,
373
+ };
374
+
375
+ this.stepper = step => () => {
376
+ this.setState(prev => ({...prev, value: prev.value + step }))
377
+ }
378
+
379
+ this.onChange = event => {
380
+ this.setState({
381
+ value: Number(event.target.value)
382
+ });
383
+ };
384
+ }
385
+
386
+ render() {
387
+ const { value } = this.state;
388
+ return (
389
+ <NumberInput
390
+ value={value}
391
+ onMinus={this.stepper(-3)}
392
+ onChange={this.onChange}
393
+ onPlus={this.stepper(3)}
394
+ inputName="input"
395
+ inputAriaLabel="number input"
396
+ minusBtnAriaLabel="minus"
397
+ plusBtnAriaLabel="plus"
398
+ />
399
+ );
400
+ }
401
+ }
402
+ ```
@@ -0,0 +1,67 @@
1
+ ---
2
+ id: Button
3
+ section: components
4
+ ---
5
+
6
+ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
7
+
8
+ ## Demos
9
+
10
+ ### Progress button
11
+
12
+ ```ts
13
+ import React from 'react';
14
+ import { Form, FormGroup, ActionGroup, InputGroup, TextInput, Button } from '@patternfly/react-core';
15
+ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
16
+
17
+ const ProgressButton: React.FunctionComponent = () => {
18
+ const [loginState, setLoginState] = React.useState<'notLoggedIn' | 'loading' | 'loggedIn'>('notLoggedIn');
19
+
20
+ return (
21
+ <Form>
22
+ <FormGroup label="Username" isRequired fieldId="progress-button-initial-login">
23
+ <TextInput
24
+ isRequired
25
+ type="text"
26
+ id="progress-button-initial-login"
27
+ name="progress-button-initial-login"
28
+ value="johndoe"
29
+ aria-label="username input"
30
+ />
31
+ </FormGroup>
32
+ <FormGroup label="Password" isRequired fieldId="progress-button-initial-password">
33
+ <TextInput
34
+ isRequired
35
+ type="password"
36
+ value="p@ssw0rd"
37
+ id="progress-button-initial-password"
38
+ name="progress-button-initial-password"
39
+ aria-label="password input"
40
+ />
41
+ </FormGroup>
42
+ <ActionGroup>
43
+ <Button
44
+ variant="primary"
45
+ onClick={
46
+ loginState === 'notLoggedIn'
47
+ ? () => {
48
+ setLoginState('loading');
49
+ setTimeout(() => {
50
+ setLoginState('loggedIn');
51
+ }, 3000);
52
+ }
53
+ : null
54
+ }
55
+ isLoading={loginState === 'loading'}
56
+ icon={loginState === 'loggedIn' ? <CheckCircleIcon /> : null}
57
+ spinnerAriaValueText="Loading..."
58
+ >
59
+ {loginState === 'notLoggedIn' && 'Link account and log in'}
60
+ {loginState === 'loading' && 'Linking account'}
61
+ {loginState === 'loggedIn' && 'Logged in'}
62
+ </Button>
63
+ </ActionGroup>
64
+ </Form>
65
+ );
66
+ };
67
+ ```
package/src/demos/Tabs.md CHANGED
@@ -444,9 +444,16 @@ TabsOpenWithSecondaryTabsDemo = () => {
444
444
  ```
445
445
 
446
446
  ### Nested tabs
447
+
447
448
  ```js isFullscreen file="./Tabs/NestedTabsDemo.js"
448
449
  ```
449
450
 
450
451
  ### Tables and tabs
452
+
451
453
  ```js isFullscreen file="./examples/Tabs/TabsAndTable.tsx"
452
454
  ```
455
+
456
+ ### Modal tabs
457
+
458
+ ```js isFullscreen file="./examples/Tabs/ModalTabs.tsx"
459
+ ```
@@ -0,0 +1,142 @@
1
+ import React from 'react';
2
+ import DashboardWrapper from '../DashboardWrapper';
3
+ import {
4
+ PageSection,
5
+ TextContent,
6
+ Text,
7
+ Gallery,
8
+ Card,
9
+ CardBody,
10
+ CardTitle,
11
+ PageSectionVariants,
12
+ Modal,
13
+ ModalVariant,
14
+ Tab,
15
+ Tabs,
16
+ TabTitleText,
17
+ List,
18
+ ListItem,
19
+ Grid,
20
+ GridItem,
21
+ TabContent
22
+ } from '@patternfly/react-core';
23
+
24
+ interface Product {
25
+ id: number;
26
+ name: string;
27
+ description: string;
28
+ }
29
+
30
+ const products: Product[] = [
31
+ {
32
+ id: 0,
33
+ name: 'PatternFly',
34
+ description: 'PatternFly is a community project that promotes design commonality and improves user experience.'
35
+ },
36
+ {
37
+ id: 1,
38
+ name: 'ActiveMQ',
39
+ description:
40
+ 'The ActiveMQ component allows messages to be sent to a JMS Queue or Topic; or messages to be consumed from a JMS Queue or Topic using Apache ActiveMQ.'
41
+ },
42
+ {
43
+ id: 2,
44
+ name: 'Apache Spark',
45
+ description: 'This documentation page covers the Apache Spark component for the Apache Camel.'
46
+ }
47
+ ];
48
+
49
+ export const ModalTabs: React.FunctionComponent = () => {
50
+ const [isModalOpen, setIsModalOpen] = React.useState(false);
51
+ const [selectedProduct, setSelectedProduct] = React.useState<Product>();
52
+ const [activeTabKey, setActiveTabKey] = React.useState<string | number>(0);
53
+
54
+ const onCardClick = React.useCallback(
55
+ (product: Product) => () => {
56
+ setSelectedProduct(product);
57
+ setIsModalOpen(true);
58
+ },
59
+ []
60
+ );
61
+
62
+ const onCardKeyPress = React.useCallback(
63
+ (product: Product) => (event: React.KeyboardEvent<HTMLElement>) => {
64
+ if (event.key === 'Enter' || event.key === ' ') {
65
+ onCardClick(product)();
66
+ }
67
+ },
68
+ []
69
+ );
70
+
71
+ const closeModal = React.useCallback(() => {
72
+ setSelectedProduct(undefined);
73
+ setIsModalOpen(false);
74
+ setActiveTabKey(0);
75
+ }, []);
76
+
77
+ const onTabSelect = React.useCallback(
78
+ (_event: React.MouseEvent<HTMLElement, MouseEvent>, tabIndex: string | number) => setActiveTabKey(tabIndex),
79
+ []
80
+ );
81
+
82
+ return (
83
+ <React.Fragment>
84
+ <DashboardWrapper mainContainerId="main-content-card-view-default-nav" breadcrumb={null}>
85
+ <PageSection variant={PageSectionVariants.light}>
86
+ <TextContent>
87
+ <Text component="h1">Projects</Text>
88
+ <Text component="p">Click any project card to view Tabs within Modals.</Text>
89
+ </TextContent>
90
+ </PageSection>
91
+ <PageSection isFilled>
92
+ <Gallery hasGutter>
93
+ {products.map(product => (
94
+ <Card
95
+ isSelectable
96
+ isSelectableRaised
97
+ isCompact
98
+ key={product.id}
99
+ onClick={onCardClick(product)}
100
+ onKeyPress={onCardKeyPress(product)}
101
+ >
102
+ <CardTitle>{product.name}</CardTitle>
103
+ <CardBody>{product.description}</CardBody>
104
+ </Card>
105
+ ))}
106
+ </Gallery>
107
+ </PageSection>
108
+ </DashboardWrapper>
109
+
110
+ {selectedProduct && (
111
+ <Modal variant={ModalVariant.small} title={selectedProduct.name} isOpen={isModalOpen} onClose={closeModal}>
112
+ <Grid hasGutter>
113
+ <GridItem>
114
+ <Tabs activeKey={activeTabKey} onSelect={onTabSelect} isSecondary>
115
+ <Tab eventKey={0} tabContentId="details-tab" title={<TabTitleText>Details</TabTitleText>} />
116
+ <Tab eventKey={1} tabContentId="doc-tab" title={<TabTitleText>Documentation</TabTitleText>} />
117
+ </Tabs>
118
+ </GridItem>
119
+ <GridItem>
120
+ <TabContent eventKey={0} id="details-tab" hidden={activeTabKey !== 0}>
121
+ {selectedProduct.description}
122
+ </TabContent>
123
+ <TabContent eventKey={1} id="doc-tab" hidden={activeTabKey !== 1}>
124
+ <List>
125
+ <ListItem>
126
+ <a>Doc link 1</a>
127
+ </ListItem>
128
+ <ListItem>
129
+ <a>Doc link 2</a>
130
+ </ListItem>
131
+ <ListItem>
132
+ <a>Doc link 3</a>
133
+ </ListItem>
134
+ </List>
135
+ </TabContent>
136
+ </GridItem>
137
+ </Grid>
138
+ </Modal>
139
+ )}
140
+ </React.Fragment>
141
+ );
142
+ };