@commercetools-uikit/collapsible-panel 0.0.0-canary-2021830134526
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/LICENSE +21 -0
- package/README.md +174 -0
- package/dist/commercetools-uikit-collapsible-panel.cjs.dev.js +392 -0
- package/dist/commercetools-uikit-collapsible-panel.cjs.js +7 -0
- package/dist/commercetools-uikit-collapsible-panel.cjs.prod.js +240 -0
- package/dist/commercetools-uikit-collapsible-panel.esm.js +374 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 commercetools GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
|
|
2
|
+
<!-- This file is created by the `yarn generate-readme` script. -->
|
|
3
|
+
|
|
4
|
+
# CollapsiblePanel
|
|
5
|
+
|
|
6
|
+
## Description
|
|
7
|
+
|
|
8
|
+
A panel to collapse and expand your content.
|
|
9
|
+
|
|
10
|
+
The component can be used in a controlled or uncontrolled manner. Please refer to the [React documentation](https://reactjs.org/docs/forms.html#controlled-components) if you are unsure what either or entails.
|
|
11
|
+
|
|
12
|
+
> Please have a look at the [Component Best Practices](<(#component-best-practices)>) to ensure that you are using the component as intended from a development and UX perspective.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
yarn add @commercetools-uikit/collapsible-panel
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm --save install @commercetools-uikit/collapsible-panel
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Additionally install the peer dependencies (if not present)
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
yarn add react
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
npm --save install react
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```jsx
|
|
37
|
+
import CollapsiblePanel from '@commercetools-uikit/collapsible-panel';
|
|
38
|
+
import Spacings from '@commercetools-uikit/spacings';
|
|
39
|
+
import Text from '@commercetools-uikit/text';
|
|
40
|
+
|
|
41
|
+
const Example = () => (
|
|
42
|
+
<Spacings.Stack>
|
|
43
|
+
{/* 1. Uncontrolled. The `CollapsiblePanel` controls its own state. You do not pass handlers or state related props. */}
|
|
44
|
+
<CollapsiblePanel header="Lorem">
|
|
45
|
+
<Text.Detail>Hello World</Text.Detail>
|
|
46
|
+
</CollapsiblePanel>;{/* 2. Controlled. You control the `CollapsiblePanel`. You do pass handlers or state related props.
|
|
47
|
+
Assume the parent rendering the `CollapsiblePanel` has `isPanelOpen` as state and a `togglePanel` as a handler. */}
|
|
48
|
+
<CollapsiblePanel
|
|
49
|
+
isClosed={this.state.isPanelOpen}
|
|
50
|
+
onToggle={this.togglePanel}
|
|
51
|
+
header="Lorem"
|
|
52
|
+
>
|
|
53
|
+
<Text.Detail>Hello World</Text.Detail>
|
|
54
|
+
</CollapsiblePanel>
|
|
55
|
+
;
|
|
56
|
+
</Spacings.Stack>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
export default Example;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Properties
|
|
63
|
+
|
|
64
|
+
| Props | Type | Required | Default | Description |
|
|
65
|
+
| ------------------------- | ----------------------------------------------------------------------------------------- | :------: | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
66
|
+
| `id` | `string` | | `uniqueId()` | An unique id for the panel header, which will also be used to generate a prefixed id for the panel content section.
<br/>
Read about `getPanelContentId` below for more about this. |
|
|
67
|
+
| `header` | `node` | ✅ | | The title being rendered at top left of the panel |
|
|
68
|
+
| `secondaryHeader` | `node` | | | A secondary header for the panel (only pass if needed) |
|
|
69
|
+
| `description` | `string` | | | If passed will be shown below the title as more information regarding the panel |
|
|
70
|
+
| `className` | `string` | | | |
|
|
71
|
+
| `isSticky` | `bool` | | | Makes the panel's header sticky in regards to the page's scroll |
|
|
72
|
+
| `headerControls` | `node` | | | Controls at the top right part of the panel |
|
|
73
|
+
| `isDisabled` | `bool` | | `false` | Disables the panel and all interactions with it |
|
|
74
|
+
| `children` | `node` | | | The actual content rendered inside the panel |
|
|
75
|
+
| `tone` | `enum`<br/>Possible values:<br/>`'urgent', 'primary'` | | | |
|
|
76
|
+
| `theme` | `enum`<br/>Possible values:<br/>`'dark', 'light'` | | `'dark'` | The main color combination of the for the panel header and container |
|
|
77
|
+
| `condensed` | `bool` | | `false` | Whenever `true` the headers and content itself
will consume less space in that to the borders are smaller and everything has less padding |
|
|
78
|
+
| `hideExpansionControls` | `bool` | | | Controls the visibility of the expansion controls on the left |
|
|
79
|
+
| `headerControlsAlignment` | `enum`<br/>Possible values:<br/>`'left', 'right'` | | `'right'` | |
|
|
80
|
+
| `isDefaultClosed` | `custom` | | | Indicates if the panel's content should be collapsed or shown by default.
<br />
Updates to this value are not respected. Only used for **uncontrolled** mode (when no`onToggle` is passed.) |
|
|
81
|
+
| `isClosed` | `bool` | | | Indicates if the panel's content should be collapsed or shown.
<br />
Component becomes \*_controlled_ when this is passed. |
|
|
82
|
+
| `onToggle` | `custom` | | | function to be triggered whenever the user clicks the top area to collapse the panel's content
<br />
Becomes required when `isClosed` is passed.
<br />
Signature: `() => void` |
|
|
83
|
+
| `horizontalConstraint` | `enum`<br/>Possible values:<br/>`6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
|
|
84
|
+
|
|
85
|
+
## Where to use
|
|
86
|
+
|
|
87
|
+
Whenever some content on a given page should be concealed and/or expandible. This often holds true for instance for detailed but hidden information of some entity to save space.
|
|
88
|
+
|
|
89
|
+
**Header**
|
|
90
|
+
|
|
91
|
+
The header of this component should follow our design and UX conventions so it looks the same across the application. It accepts a `node` to accompany the two scenarios:
|
|
92
|
+
|
|
93
|
+
1. Given the `CollapsiblePanel` is _condensed_
|
|
94
|
+
|
|
95
|
+
Whenever the component is configured to be `condensed` all content pased via the `header` will be wrapped in a `<Text.Detail />`. For this use case please ensure that _no combinations of components_ are passed via the `header`.
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import CollapsiblePanel from '@commercetools-uikit/collapsible-panel';
|
|
99
|
+
|
|
100
|
+
<CollapsiblePanel condensed={true} header={'My title'}>
|
|
101
|
+
<YourComponentAsContentOfThePanel />
|
|
102
|
+
</CollapsiblePanel>;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
2. Given the `CollapsiblePanel` is _not condensed_
|
|
106
|
+
|
|
107
|
+
For this use case you will need to explicitly pass the `header` wrapped by the `<CollapsiblePanel.Header />` component to automatically ensure it follows our designs (enforced by the `<CollapsiblePanel.Header />`).
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
import CollapsiblePanel from '@commercetools-uikit/collapsible-panel';
|
|
111
|
+
|
|
112
|
+
<CollapsiblePanel
|
|
113
|
+
header={
|
|
114
|
+
<CollapsiblePanel.Header>
|
|
115
|
+
<FormattedMessage {...messages.title} />
|
|
116
|
+
</CollapsiblePanel.Header>
|
|
117
|
+
}
|
|
118
|
+
>
|
|
119
|
+
<YourComponentAsContentOfThePanel />
|
|
120
|
+
</CollapsiblePanel>;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
3. Passing a combination of components (e.g. label and input)
|
|
124
|
+
|
|
125
|
+
Rendering any input(s) inside the `header` is allowed, but there are certain contraints that need to be taken into account:
|
|
126
|
+
|
|
127
|
+
- You can only render a _maximum amount of 3_ components inside the `header`.
|
|
128
|
+
- Given a combination of label and input
|
|
129
|
+
- Then the input's _label should be bold_ and the _input only a `<TextInput />`_
|
|
130
|
+
- All has to be _vertically aligned_ in the `header` container.
|
|
131
|
+
|
|
132
|
+
**Theme**
|
|
133
|
+
|
|
134
|
+
The component supports themes (dark and light) to enable nesting of collapsible panels inside one another.
|
|
135
|
+
|
|
136
|
+
- Given the background of the parent is `dark`
|
|
137
|
+
- Then the child needs to be `light` for better accessibility and visibility
|
|
138
|
+
|
|
139
|
+
**Condensed**
|
|
140
|
+
|
|
141
|
+
There are a some restrictions given using `condensed={true}`
|
|
142
|
+
|
|
143
|
+
1. Nothing complex is passed as the `header`
|
|
144
|
+
|
|
145
|
+
- Nor button or inputs or anything that is not within title itself
|
|
146
|
+
|
|
147
|
+
2. The title should be only (if possible) be a string or a combination or text components
|
|
148
|
+
|
|
149
|
+
- Everything is automatically wrapped within a `<Text.Detail />`
|
|
150
|
+
|
|
151
|
+
**SecondaryHeader**
|
|
152
|
+
|
|
153
|
+
The `secondaryHeader` allow rendering some secondary information in addition to the title.
|
|
154
|
+
|
|
155
|
+
It accepts a `node` but with few restrictions:
|
|
156
|
+
|
|
157
|
+
1. _Bold text is allowed_ while the text component is `<Text.Detail />`
|
|
158
|
+
1. Text size should not exceed the font size of `<Text.Detail />`
|
|
159
|
+
|
|
160
|
+
**headerControls**
|
|
161
|
+
|
|
162
|
+
The `headerControls` allows rendering a component which should only contain buttons or links. Apart from that there is one more limitation:
|
|
163
|
+
|
|
164
|
+
1. You can only render a _maximum amount of 3 button_ inside the `headerControls`
|
|
165
|
+
|
|
166
|
+
## Static methods
|
|
167
|
+
|
|
168
|
+
### `CollapsiblePanel.getPanelContentId`
|
|
169
|
+
|
|
170
|
+
Returns the generated `id` used for the wrapper of the panel content section. It is used for setting the `aria-controls` attribute on the header and can also be useful for finding the child element when testing.
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
CollapsiblePanel.getPanelContentId('example'); // -> panel-content-example
|
|
174
|
+
```
|