Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds accents slot to rh-accordion-header #1505

Merged
merged 18 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-comics-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rhds/elements": patch
---

`<rh-accordion>`: added a accents slot with placement options as inline and bottom
8 changes: 7 additions & 1 deletion docs/_plugins/rhds.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,13 @@ module.exports = function(eleventyConfig, { tagsToAlphabetize }) {
eleventyConfig.addCollection('sortedDevelopers', async function(collectionApi) {
const developersCollection = collectionApi.getFilteredByTags('developers');
return developersCollection.sort((a, b) => {
if (a.data.order > b.data.order) { return 1; } else if (a.data.order < b.data.order) { return -1; } else { return 0; }
if (a.data.order > b.data.order) {
return 1;
} else if (a.data.order < b.data.order) {
return -1;
} else {
return 0;
}
});
});

Expand Down
3 changes: 3 additions & 0 deletions docs/scss/components/_component-status-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
display: flex;
justify-content: space-between;
align-items: flex-end;
p {
font-size: var(--rh-font-size-body-text-sm);
}
}

.component-status-list-container {
Expand Down
9 changes: 9 additions & 0 deletions elements/rh-accordion/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { RhAccordion } from './rh-accordion';

import { createContextWithRoot } from '@patternfly/pfe-core/functions/context.js';

export interface RhAccordionContext {
accents?: 'inline' | 'bottom';
}

export const context = createContextWithRoot<RhAccordionContext>(Symbol('rh-accordion-context'));
71 changes: 71 additions & 0 deletions elements/rh-accordion/demo/accents.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<section id="inline">
<h3>Inline</h3>
<rh-accordion>
<rh-accordion-header>
<h4>Item One</h4>
<rh-tag slot="accents" color="green" variant="filled" icon="info" icon-set="fas">Green</rh-tag>
<rh-tag slot="accents" color="red" variant="filled" icon="info" icon-set="fas">Red</rh-tag>
<rh-tag slot="accents" color="orange" variant="filled" icon="bell" icon-set="fas">Orange</rh-tag>
<rh-tag slot="accents" color="purple" variant="filled" icon="ban" icon-set="fas">Purple</rh-tag>
</rh-accordion-header>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
<rh-accordion-header>
<h4>Item Two</h4>
<rh-tag slot="accents" color="green" variant="filled" icon="info" icon-set="fas">Green</rh-tag>
</rh-accordion-header>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
<rh-accordion-header>
<h4>Item Three</h4>
<rh-tag slot="accents" color="red" variant="filled" icon="info" icon-set="fas">Red</rh-tag>
</rh-accordion-header>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
</rh-accordion>
</section>


<section id="bottom">
<h3>Bottom</h3>
<rh-accordion accents="bottom">
<rh-accordion-header>
<h4>Item One</h4>
<rh-tag slot="accents" color="green" variant="filled" icon="info" icon-set="fas">Green</rh-tag>
<rh-tag slot="accents" color="red" variant="filled" icon="info" icon-set="fas">Red</rh-tag>
<rh-tag slot="accents" color="orange" variant="filled" icon="bell" icon-set="fas">Orange</rh-tag>
<rh-tag slot="accents" color="purple" variant="filled" icon="ban" icon-set="fas">Purple</rh-tag>
</rh-accordion-header>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
<rh-accordion-header>
<h4>Item Two</h4>
<rh-tag slot="accents" color="green" variant="filled" icon="info" icon-set="fas">Green</rh-tag>
</rh-accordion-header>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
<rh-accordion-header>
<h4>Item Three</h4>
<rh-tag slot="accents" color="red" variant="filled" icon="info" icon-set="fas">Red</rh-tag>
</rh-accordion-header>
<rh-accordion-panel>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</rh-accordion-panel>
</rh-accordion>
</section>

<style>
#inline, #bottom {
margin-block-end: var(--rh-space-3xl, 48px);
}
</style>

<script type="module">
import '@rhds/elements/rh-accordion/rh-accordion.js';
import '@rhds/elements/rh-tag/rh-tag.js';
</script>
27 changes: 24 additions & 3 deletions elements/rh-accordion/rh-accordion-header.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,27 @@ a {

span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: calc(100% - var(--rh-space-xl, 24px));
text-align: start;
}

[part="container"] {
display: flex;
gap: var(--rh-space-xl, 24px);
container-type: inline-size;
}

#header-container {
display: flex;
flex-direction: column;
gap: var(--rh-space-md, 8px);
}

[part="accents"] {
display: flex;
flex-wrap: wrap;
gap: var(--rh-space-md, 8px);
}

#button[aria-expanded="true"] #icon {
rotate: calc(var(--_isRTL, -1) * 180deg);
}
Expand Down Expand Up @@ -145,3 +160,9 @@ span {
inset-block: 0;
inset-inline-start: 0;
}

@container (min-width: 576px) {
#header-container:not(.bottom) {
flex-direction: row;
}
}
24 changes: 21 additions & 3 deletions elements/rh-accordion/rh-accordion-header.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import type { RhAccordion } from './rh-accordion.js';
import type { RhAccordionContext } from './context.js';

import { html, LitElement } from 'lit';
import { classMap } from 'lit/directives/class-map.js';
import { customElement } from 'lit/decorators/custom-element.js';
import { property } from 'lit/decorators/property.js';
import { ifDefined } from 'lit/directives/if-defined.js';

import { Logger } from '@patternfly/pfe-core/controllers/logger.js';
import { getRandomId } from '@patternfly/pfe-core/functions/random.js';

import { DirController } from '../../lib/DirController.js';
import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/consumer.js';

import { consume } from '@lit/context';

import { context } from './context.js';

import styles from './rh-accordion-header.css';

const isPorHeader =
Expand Down Expand Up @@ -38,8 +44,8 @@ export class AccordionHeaderChangeEvent extends Event {
* @slot
* We expect the light DOM of the rh-accordion-header to be a heading level tag (h1, h2, h3, h4, h5, h6)
* @slot accents
* These elements will appear inline with the accordion header, between the header and the chevron
* (or after the chevron and header in disclosure mode).
* These elements will appear inline by default with the header title, between the header and the chevron
* (or after the chevron and header in disclosure mode). There is an option to set the accents placement to bottom
*
* @fires {AccordionHeaderChangeEvent} change - when the open panels change
*
Expand All @@ -61,10 +67,15 @@ export class RhAccordionHeader extends LitElement {

@property({ reflect: true, attribute: 'heading-tag' }) headingTag?: string;

/** @deprecated */
@property({ reflect: true }) icon = 'angle-down';

@colorContextConsumer() private on?: ColorTheme;

@consume({ context, subscribe: true })
@property({ attribute: false })
private ctx?: RhAccordionContext;

#generatedHtag?: HTMLHeadingElement;

#logger = new Logger(this);
Expand Down Expand Up @@ -121,13 +132,20 @@ export class RhAccordionHeader extends LitElement {
}

#renderHeaderContent() {
const { accents } = this.ctx ?? {};
const headingText = this.headingText?.trim() ?? this.#header?.textContent?.trim();

return html`
<button id="button"
class="toggle"
aria-expanded="${String(!!this.expanded) as 'true' | 'false'}">
<span part="text">${headingText ?? html`
<span id="header-container" class="${ifDefined(accents)}">
<span part="text">${headingText ?? html`
<slot></slot>`}
</span>
<span part="accents">
<slot name="accents"></slot>
</span>
</span>
<svg id="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path d="M201.4 374.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 306.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"/>
Expand Down
25 changes: 25 additions & 0 deletions elements/rh-accordion/rh-accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { customElement } from 'lit/decorators/custom-element.js';
import { property } from 'lit/decorators/property.js';

import { observed } from '@patternfly/pfe-core/decorators/observed.js';
import { provide } from '@lit/context';

import { RovingTabindexController } from '@patternfly/pfe-core/controllers/roving-tabindex-controller.js';

Expand All @@ -16,8 +17,11 @@ import { Logger } from '@patternfly/pfe-core/controllers/logger.js';
import { RhAccordionHeader, AccordionHeaderChangeEvent } from './rh-accordion-header.js';
import { RhAccordionPanel } from './rh-accordion-panel.js';

import { context, type RhAccordionContext } from './context.js';

import styles from './rh-accordion.css';


export class AccordionExpandEvent extends ComposedEvent {
constructor(
public toggle: RhAccordionHeader,
Expand Down Expand Up @@ -48,6 +52,10 @@ export class AccordionCollapseEvent extends ComposedEvent {
* @slot
* Place the `rh-accordion-header` and `rh-accordion-panel` elements here.
*
* @attr accents
* Position accents in the header either inline or bottom
* {@default inline}
*
*/
@customElement('rh-accordion')
export class RhAccordion extends LitElement {
Expand All @@ -71,6 +79,14 @@ export class RhAccordion extends LitElement {
return event instanceof AccordionHeaderChangeEvent;
}

/**
* Sets accordion header's accents position to inline or bottom
*/
@property({
attribute: true,
reflect: true,
}) accents?: 'inline' | 'bottom';

/**
* Sets and reflects the currently expanded accordion 0-based indexes.
* Use commas to separate multiple indexes.
Expand Down Expand Up @@ -101,6 +117,12 @@ export class RhAccordion extends LitElement {
}
}

get #ctx(): RhAccordionContext {
const accents = this.accents ? this.accents : 'inline';
return { accents };
}


@observed(function largeChanged(this: RhAccordion) {
[...this.headers, ...this.panels].forEach(el => el.toggleAttribute('large', this.large));
})
Expand Down Expand Up @@ -128,6 +150,8 @@ export class RhAccordion extends LitElement {

#mo = new MutationObserver(() => this.#init());

@provide({ context }) private ctx = this.#ctx;

connectedCallback() {
super.connectedCallback();
this.addEventListener('change', this.#onChange as EventListener);
Expand All @@ -153,6 +177,7 @@ export class RhAccordion extends LitElement {
}
}
});
this.ctx = this.#ctx;
}

/**
Expand Down
Loading