|
1 | | -# PFElements Tabs Element |
| 1 | +# PatternFly Elements Tabs |
| 2 | + |
| 3 | +Read more about Tabs in the [PatternFly Elements Tabs documentation](https://patternflyelements.org/components/tabs) |
2 | 4 |
|
3 | | -## Usage |
4 | | - |
5 | | -```html |
6 | | -<pfe-tabs> |
7 | | - <pfe-tab role="heading" slot="tab">Tab 1</pfe-tab> |
8 | | - <pfe-tab-panel role="region" slot="panel"> |
9 | | - <h2>Content 1</h2> |
10 | | - <p>Tab 1 panel content.</p> |
11 | | - </pfe-tab-panel> |
12 | | - <pfe-tab role="heading" slot="tab">Tab 2</pfe-tab> |
13 | | - <pfe-tab-panel role="region" slot="panel"> |
14 | | - <h2>Content 2</h2> |
15 | | - <p>Tab 2 panel content.</p> |
16 | | - </pfe-tab-panel> |
17 | | -</pfe-tabs> |
18 | | -``` |
19 | | - |
20 | | -For each `pfe-tab`, you are responsible for setting the `role="heading"`and |
21 | | -`slot="tab"`. |
22 | | - |
23 | | -For each `pfe-tab-panel`, you are responsible for setting `role="region"` and |
24 | | -`slot="panel"`. |
25 | | - |
26 | | -## Slots |
| 5 | +## Installation |
27 | 6 |
|
28 | | -### Default slot in pfe-tabs |
29 | | - |
30 | | -Place the `pfe-tab` and `pfe-tab-panel` elements here. |
31 | | - |
32 | | -### Default slot in pfe-tab |
33 | | - |
34 | | -Add the heading for your tab here. |
35 | | - |
36 | | -### Default slot in pfe-tab-panel |
37 | | - |
38 | | -Add the content for your tab panel here. |
39 | | - |
40 | | -## Attributes |
41 | | -**`variant`** (observed) |
42 | | - |
43 | | -Possible values are: |
44 | | -- `wind`: Borders are removed, only an accent colored indicator appears under the active heading. |
45 | | -- `earth`: Headings are encased in a block. The active heading has an accent colored border on one side. |
46 | | -* Note - when using earth with a white background you should set the padding-left, padding-right, and padding-bottom to 0, so it lines up with the wind variant. |
| 7 | +Load `<pfe-tabs>` via CDN: |
47 | 8 |
|
48 | 9 | ```html |
49 | | -<pfe-tabs variant="wind"> |
50 | | - ... |
51 | | -</pfe-tabs> |
| 10 | +<script src="https://unpkg.com/@patternfly/pfe-tabs?module"></script> |
52 | 11 | ``` |
53 | 12 |
|
54 | | -**`vertical`** (observed) |
| 13 | +Or, if you are using [NPM](https://npm.im), install it |
55 | 14 |
|
56 | | -Orients the tabs vertically on the left and pushes the content panes to the right. |
57 | | - |
58 | | -```html |
59 | | -<pfe-tabs vertical> |
60 | | - ... |
61 | | -</pfe-tabs> |
| 15 | +```bash |
| 16 | +npm install @patternfly/pfe-tabs |
62 | 17 | ``` |
63 | 18 |
|
64 | | -**`selected-index`** (observed) |
65 | | - |
66 | | -Sets and reflects the currently selected tab index. |
| 19 | +Then once installed, import it to your application: |
67 | 20 |
|
68 | | -```html |
69 | | -<pfe-tabs selected-index="2"> |
70 | | - ... |
71 | | -</pfe-tabs> |
| 21 | +```js |
| 22 | +import '@patternfly/pfe-tabs'; |
72 | 23 | ``` |
73 | 24 |
|
74 | | -**`context`** (observed) |
75 | | - |
76 | | -Changes the context of the call-to-action to one of 3 possible options: |
77 | | -- `light` (default) |
78 | | -- `dark` |
79 | | -- `saturated` |
80 | | - |
81 | | -This will override any context being passed from a parent component and will add a style attribute setting the `--context` variable. |
82 | | - |
83 | | -**`tab-history`** (observed) |
84 | | - |
85 | | -Updates window.history and the URL to create sharable links. With the |
86 | | -`tab-history` attribute, the tabs and each tab *must* have an `id`. |
87 | | - |
88 | | -The URL pattern will be `?{id-of-tabs}={id-of-selected-tab}`. In the example |
89 | | -below, selecting "Tab 2" will update the URL as follows: `?my-tabs=tab2`. |
90 | | - |
91 | | -```html |
92 | | -<pfe-tabs tab-history id="my-tabs"> |
93 | | - <pfe-tab role="heading" slot="tab" id="tab1">Tab 1</pfe-tab> |
94 | | - <pfe-tab-panel role="region" slot="panel"> |
95 | | - <h2>Content 1</h2> |
96 | | - <p>Tab 1 panel content.</p> |
97 | | - </pfe-tab-panel> |
98 | | - <pfe-tab role="heading" slot="tab" id="tab2">Tab 2</pfe-tab> |
99 | | - <pfe-tab-panel role="region" slot="panel"> |
100 | | - <h2>Content 2</h2> |
101 | | - <p>Tab 2 panel content.</p> |
102 | | - </pfe-tab-panel> |
103 | | -</pfe-tabs> |
104 | | -``` |
105 | | - |
106 | | -*Note:* This feature is not supported in IE11. |
107 | | - |
108 | | -## Using the URL to open a specific tab |
109 | | - |
110 | | -By default, `pfe-tabs` will read the URL and look for a query string parameter |
111 | | -that matches the id of a `pfe-tabs` component and a value of a specific |
112 | | -`pfe-tab`. |
113 | | - |
114 | | -For example, `?my-tabs=tab2` would open the second tab in the code sample below. |
115 | | -"my-tabs" is equal to the id of the `pfe-tabs` component and "tab2" is equal to |
116 | | -the id of the second tab in the tab set. |
| 25 | +## Usage |
117 | 26 |
|
118 | 27 | ```html |
119 | | -<pfe-tabs id="my-tabs"> |
120 | | - <pfe-tab role="heading" slot="tab" id="tab1">Tab 1</pfe-tab> |
| 28 | +<pfe-tabs> |
| 29 | + <pfe-tab role="heading" slot="tab">Tab 1</pfe-tab> |
121 | 30 | <pfe-tab-panel role="region" slot="panel"> |
122 | 31 | <h2>Content 1</h2> |
123 | 32 | <p>Tab 1 panel content.</p> |
124 | 33 | </pfe-tab-panel> |
125 | | - <pfe-tab role="heading" slot="tab" id="tab2">Tab 2</pfe-tab> |
| 34 | + <pfe-tab role="heading" slot="tab">Tab 2</pfe-tab> |
126 | 35 | <pfe-tab-panel role="region" slot="panel"> |
127 | 36 | <h2>Content 2</h2> |
128 | 37 | <p>Tab 2 panel content.</p> |
129 | 38 | </pfe-tab-panel> |
130 | 39 | </pfe-tabs> |
131 | 40 | ``` |
132 | 41 |
|
133 | | -In the event that a tab with the supplied id in the URL does not exist, |
134 | | -`pfe-tabs` will fall back to the `selected-index` attribute if one is supplied |
135 | | -in the markup, or the first tab if `selected-index` is not provided. |
136 | | - |
137 | | -*Note:* This feature is not supported in IE11. |
138 | | - |
139 | | -## Events |
140 | | - |
141 | | -### pfe-tabs:shown-tab |
142 | | - |
143 | | -Fires when a new tab is selected. The `event.detail.tab` will be the tab that has been selected. |
144 | | - |
145 | | -### pfe-tabs:hidden-tab |
146 | | - |
147 | | -Fires when a selected tab is no longer the selected tab. The `event.detail.tab` will be the tab that is no longer selected. |
148 | | - |
149 | | -## Styling |
150 | | - |
151 | | -| Theme hook | Description | Default | |
152 | | -| -------------- | ----------- | ------- | |
153 | | -| `--pfe-tabs--Display` | | block | |
154 | | -| `--pfe-tabs--Padding` | Tab padding and panel padding | 0 | |
155 | | -| `--pfe-tabs__tabs--FlexDirection` | | row | |
156 | | -| `--pfe-tabs__tabs--Width` | | auto | |
157 | | -| `--pfe-tabs__tabs--Padding` | | 0 | |
158 | | -| `--pfe-tabs__tabs--BorderTop` | | 0 | |
159 | | -| `--pfe-tabs__tabs--BorderRight` | | 0 | |
160 | | -| `--pfe-tabs__tabs--BorderLeft` | | 0 | |
161 | | -| `--pfe-tabs__tabs--BorderColor` | | var(--pfe-theme--color--surface--border, #d2d2d2) | |
162 | | -| `--pfe-tabs__tabs--BorderBottom` | | var(--pfe-theme--ui--border-width, 1px) var(--pfe-theme--ui--border-style, solid) var(--pfe-tabs__tabs--BorderColor, var(--pfe-theme--color--surface--border, #d2d2d2)) | |
163 | | -| `--pfe-tabs__panels--Width` | | auto | |
164 | | -| `--pfe-tabs--BackgroundColor` | | transparent | |
165 | | -| `--pfe-tabs--BackgroundColor--inactive` | | var(--pfe-theme--color--surface--lighter, #f0f0f0) | |
166 | | -| `--pfe-tabs--Color` | Default tab text color | var(--pfe-theme--color--text--muted, #6a6e73) | |
167 | | -| `--pfe-tabs--BorderColor--hover` | | #b8bbbe | |
168 | | -| `--pfe-tabs--BorderWidth` | | var(--pfe-theme--ui--border-width--active, 3px) | |
169 | | -| `--pfe-tabs__tab--FontSize` | | var(--pfe-theme--font-size, 1rem) | |
170 | | -| `--pfe-tabs__tab--Margin` | | 0 0 calc( var(--pfe-theme--ui--border-width, 1px) * -1) | |
171 | | -| `--pfe-tabs__tab--PaddingTop` | | var(--pfe-theme--container-padding, 1rem) | |
172 | | -| `--pfe-tabs__tab--PaddingBottom` | | var(--pfe-theme--container-padding, 1rem) | |
173 | | -| `--pfe-tabs__tab--PaddingRight` | | calc(var(--pfe-theme--container-padding, 1rem) * 2) | |
174 | | -| `--pfe-tabs__tab--PaddingLeft` | | calc(var(--pfe-theme--container-padding, 1rem) * 2) | |
175 | | -| `--pfe-tabs__tab--TextTransform` | | none | |
176 | | -| `--pfe-tabs--Color--focus` | | var(--pfe-tabs--focus, var(--pfe-theme--color--text, #151515)) | |
177 | | -| `--pfe-tabs--highlight` | Border style for selected tab | var(--pfe-theme--color--ui-accent, #06c) | |
178 | | -| `--pfe-tabs--BorderColor` | Border style for selected tab | var(--pfe-tabs--highlight, var(--pfe-theme--color--ui-accent, #06c)) | |
179 | | -| `--pfe-tabs--focus` | | var(--pfe-theme--color--link, #06c) | |
180 | | -| `--pfe-tabs__panel--BackgroundColor` | | transparent | |
181 | | -| `--pfe-tabs__panel--Padding` | | var(--pfe-theme--container-spacer, 1rem) | |
182 | | -| `--pfe-tabs__panel--BorderTop` | | 0 | |
183 | | -| `--pfe-tabs__panel--BorderRight` | | 0 | |
184 | | -| `--pfe-tabs__panel--BorderBottom` | | 0 | |
185 | | -| `--pfe-tabs__panel--BorderLeft` | | 0 | |
186 | | - |
187 | | -## Test |
188 | | - |
189 | | - npm run test |
190 | | - |
191 | | -## Build |
192 | | - |
193 | | - npm run build |
194 | | - |
195 | | -## Demo |
196 | | - |
197 | | -From the PFElements root directory, run: |
198 | | - |
199 | | - npm start |
200 | | - |
201 | | -## Code style |
202 | | - |
203 | | -Tabs (and all PFElements) use [Prettier][prettier] to auto-format JS and JSON. The style rules get applied when you commit a change. If you choose to, you can [integrate your editor][prettier-ed] with Prettier to have the style rules applied on every save. |
204 | | - |
205 | | -[prettier]: https://github.com/prettier/prettier/ |
206 | | -[prettier-ed]: https://github.com/prettier/prettier/#editor-integration |
207 | | -[web-component-tester]: https://github.com/Polymer/web-component-tester |
0 commit comments