Skip to content

Commit 17e15d9

Browse files
bennypowerszeroedin
andcommitted
feat(tabs)!: migrate pfe-tabs to lit
**Features** - add CSS parts **Fixes** - add {{version}} to element classes - rename `pfeEvent` to `deprecatedCustomEvent` **Tests** - e2e tests with page object model - build demo with optional shadowroot **Docs** - add CSS to demo page for tabs (#1835) - rearrange docs urls - inline docs - refactor docs page - add changeset - use pfe-styles Co-Authored-By: Steven Spriggs <steven.spriggs@gmail.com>
1 parent 6629d4c commit 17e15d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2157
-6937
lines changed

.changeset/tabs.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"@patternfly/pfe-tabs": major
3+
---
4+
5+
## 🔥 Migrate to Lit
6+
7+
This release migrates `<pfe-tabs>` to LitElement.
8+
9+
### NEW: CSS Shadow Parts!
10+
- Adds `tabs` and `panels` CSS parts to `<pfe-tabs>`
11+
- Adds `container` CSS part to `<pfe-tab-panel>`
12+
13+
### Breaking Changes
14+
- Initial render is now [asynchronous](https://lit.dev/docs/components/lifecycle/#reactive-update-cycle).
15+
If your code assumes that shadow DOM is ready once the element is constructed, update it to `await element.updateComplete`
16+
17+
See [docs](https://patternflyelements.org/components/tabs/) for more info

elements/pfe-tabs/.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

elements/pfe-tabs/README.md

Lines changed: 16 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1,207 +1,41 @@
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)
24

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
276

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:
478

489
```html
49-
<pfe-tabs variant="wind">
50-
...
51-
</pfe-tabs>
10+
<script src="https://unpkg.com/@patternfly/pfe-tabs?module"></script>
5211
```
5312

54-
**`vertical`** (observed)
13+
Or, if you are using [NPM](https://npm.im), install it
5514

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
6217
```
6318

64-
**`selected-index`** (observed)
65-
66-
Sets and reflects the currently selected tab index.
19+
Then once installed, import it to your application:
6720

68-
```html
69-
<pfe-tabs selected-index="2">
70-
...
71-
</pfe-tabs>
21+
```js
22+
import '@patternfly/pfe-tabs';
7223
```
7324

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
11726

11827
```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>
12130
<pfe-tab-panel role="region" slot="panel">
12231
<h2>Content 1</h2>
12332
<p>Tab 1 panel content.</p>
12433
</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>
12635
<pfe-tab-panel role="region" slot="panel">
12736
<h2>Content 2</h2>
12837
<p>Tab 2 panel content.</p>
12938
</pfe-tab-panel>
13039
</pfe-tabs>
13140
```
13241

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
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { pfeCustomElementsManifestConfig } from '@patternfly/pfe-tools/custom-elements-manifest.js';
2+
3+
export default pfeCustomElementsManifestConfig({
4+
globs: ['pfe-*.ts'],
5+
});

0 commit comments

Comments
 (0)