-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
web component accordion #26547
Merged
brianchristopherbrady
merged 53 commits into
web-components-v3
from
user/brianbrady/web-component-accordion
Feb 21, 2023
Merged
web component accordion #26547
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
9b169b3
accordion and accordion item init
brianchristopherbrady a19b201
yarn change
brianchristopherbrady 21b9718
updates docs
brianchristopherbrady 26e9f06
updates accordion item styles
brianchristopherbrady 752dd11
code formatting
brianchristopherbrady 949f13f
updates imports
brianchristopherbrady 4612dc6
adds v9 appearance sizes
brianchristopherbrady 13e09c4
updates attribute name to align with fluent v9
brianchristopherbrady eac140c
adds alternative stories for accordion with custom icons
brianchristopherbrady 6b6af66
adds docs
brianchristopherbrady c9b3db4
updates storybook
brianchristopherbrady 88811bf
updates changelog
brianchristopherbrady ae4ae63
removes dead code
brianchristopherbrady aebbbe8
removes dynamic icons from sb
brianchristopherbrady 7430284
removes dead code
brianchristopherbrady a52c5df
adds accordion README
brianchristopherbrady a022811
moves accordion readme to accordion directory
brianchristopherbrady 00f69f7
updates docs
brianchristopherbrady 8d2614e
updates accordion docs
brianchristopherbrady bab28ac
updates docs
brianchristopherbrady 165dd0a
updates docs
brianchristopherbrady c4c86d0
fixes docs
brianchristopherbrady 30d287e
fixes exports
brianchristopherbrady afbb81e
adds display helper to styles
brianchristopherbrady 531667b
optimizes styles
brianchristopherbrady 856ca15
updates html helper to use html.partial
brianchristopherbrady 82179e5
Merge branch 'web-components-v3' into user/brianbrady/web-component-aβ¦
brianchristopherbrady b3dca90
optimizes styles
brianchristopherbrady faa1593
exports directly on class
brianchristopherbrady 23f8fbc
removes html helper
brianchristopherbrady f672592
removes arg tables from stories
brianchristopherbrady 90c52f9
Merge branch 'web-components-v3' into user/brianbrady/web-component-aβ¦
brianchristopherbrady a49bf1e
sorts exports alphabetically
brianchristopherbrady ff3f62c
api report
brianchristopherbrady 81638aa
Merge branch 'web-components-v3' of https://github.com/microsoft/flueβ¦
brianchristopherbrady b7adbef
Merge branch 'web-components-v3' into user/brianbrady/web-component-aβ¦
brianchristopherbrady 63cab83
flattens accordion componnent folders
brianchristopherbrady 365b69f
removes comment
brianchristopherbrady 2784298
updates styles
brianchristopherbrady 442ef87
optimizes styles
brianchristopherbrady 2df5488
Merge branch 'web-components-v3' of https://github.com/microsoft/flueβ¦
brianchristopherbrady ee64492
Merge branch 'web-components-v3' into user/brianbrady/web-component-aβ¦
brianchristopherbrady 9ab33e5
updates attributes
brianchristopherbrady 5cd9311
removes renaming of definition import
brianchristopherbrady 812e29b
removes attribute syntax
brianchristopherbrady 8eb320a
adds attr
brianchristopherbrady f9b8058
reverts api-report
brianchristopherbrady 12d21a5
removes dead code
brianchristopherbrady fd1412e
updates styles
brianchristopherbrady a0f1091
consolidates stories into one
brianchristopherbrady 3fbc05f
updates docs
brianchristopherbrady 8c2dd51
Merge branch 'web-components-v3' into user/brianbrady/web-component-aβ¦
brianchristopherbrady 11b3852
adds display helper to accordion styles
brianchristopherbrady File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-web-components-ee0dceff-c555-429c-b688-92aa40dc7f5e.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "feat(accordion): Add accordion web component", | ||
"packageName": "@fluentui/web-components", | ||
"email": "brianbrady@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/web-components/src/accordion-item/accordion-item.definition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { FluentDesignSystem } from '../fluent-design-system.js'; | ||
import { AccordionItem } from './accordion-item.js'; | ||
import { styles } from './accordion-item.styles.js'; | ||
import { template } from './accordion-item.template.js'; | ||
|
||
/** | ||
* The Fluent AccordionItem Element. Implements {@link @microsoft/fast-foundation#AccordionItem }, | ||
* {@link @microsoft/fast-foundation#accordionItemTemplate} | ||
* | ||
* | ||
* @public | ||
* @remarks | ||
* HTML Element: \<fluent-accordion-item\> | ||
*/ | ||
export const definition = AccordionItem.compose({ | ||
name: `${FluentDesignSystem.prefix}-accordion-item`, | ||
template, | ||
styles, | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/web-components/src/accordion-item/accordion-item.options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ValuesOf } from '@microsoft/fast-foundation'; | ||
|
||
/** | ||
* An Accordion Item header font size can be small, medium, large, and extra-large | ||
*/ | ||
export const AccordionItemSize = { | ||
small: 'small', | ||
medium: 'medium', | ||
large: 'large', | ||
extraLarge: 'extra-large', | ||
} as const; | ||
|
||
/** | ||
* Applies font size to accordion header | ||
* @public | ||
*/ | ||
export type AccordionItemSize = ValuesOf<typeof AccordionItemSize>; | ||
|
||
/** | ||
* An Accordion Item expand/collapse icon can appear at the start or end of the accordion | ||
*/ | ||
export const AccordionItemExpandIconPosition = { | ||
start: 'start', | ||
end: 'end', | ||
} as const; | ||
|
||
/** | ||
* Applies expand/collapse icon position | ||
* @public | ||
*/ | ||
export type AccordionItemExpandIconPosition = ValuesOf<typeof AccordionItemExpandIconPosition>; |
218 changes: 218 additions & 0 deletions
218
packages/web-components/src/accordion-item/accordion-item.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
import { css } from '@microsoft/fast-element'; | ||
import { display } from '@microsoft/fast-foundation'; | ||
import { | ||
borderRadiusMedium, | ||
borderRadiusSmall, | ||
colorNeutralForeground1, | ||
colorNeutralForegroundDisabled, | ||
colorStrokeFocus1, | ||
colorStrokeFocus2, | ||
colorTransparentBackground, | ||
fontFamilyBase, | ||
fontSizeBase200, | ||
fontSizeBase300, | ||
fontSizeBase400, | ||
fontSizeBase500, | ||
fontWeightRegular, | ||
lineHeightBase200, | ||
lineHeightBase300, | ||
lineHeightBase400, | ||
lineHeightBase500, | ||
spacingHorizontalM, | ||
spacingHorizontalMNudge, | ||
spacingHorizontalS, | ||
} from '../theme/design-tokens.js'; | ||
|
||
export const styles = css` | ||
${display('block')} | ||
|
||
:host { | ||
max-width: fit-content; | ||
} | ||
|
||
.heading { | ||
height: 44px; | ||
display: grid; | ||
position: relative; | ||
vertical-align: middle; | ||
padding-inline: ${spacingHorizontalM} ${spacingHorizontalMNudge}; | ||
border-radius: ${borderRadiusMedium}; | ||
font-family: ${fontFamilyBase}; | ||
font-size: ${fontSizeBase300}; | ||
font-weight: ${fontWeightRegular}; | ||
line-height: ${lineHeightBase300}; | ||
grid-template-columns: auto auto 1fr auto; | ||
} | ||
|
||
.heading-content { | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.button { | ||
box-sizing: border-box; | ||
appearance: none; | ||
border: none; | ||
outline: none; | ||
text-align: start; | ||
cursor: pointer; | ||
font-family: inherit; | ||
height: 44px; | ||
color: ${colorNeutralForeground1}; | ||
background: ${colorTransparentBackground}; | ||
line-height: ${lineHeightBase300}; | ||
height: auto; | ||
padding: 0; | ||
font-size: inherit; | ||
grid-column: auto / span 2; | ||
grid-row: 1; | ||
} | ||
|
||
.button::before { | ||
content: ''; | ||
position: absolute; | ||
inset: 0px; | ||
cursor: pointer; | ||
border-radius: ${borderRadiusSmall}; | ||
} | ||
|
||
.icon { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
pointer-events: none; | ||
position: relative; | ||
height: 100%; | ||
padding-right: ${spacingHorizontalS}; | ||
grid-column: 1 / span 1; | ||
grid-row: 1; | ||
} | ||
|
||
.region { | ||
margin: 0 ${spacingHorizontalM}; | ||
} | ||
|
||
::slotted([slot='start']), | ||
::slotted([slot='end']) { | ||
justify-content: center; | ||
align-items: center; | ||
padding-right: ${spacingHorizontalS}; | ||
grid-column: 2 / span 1; | ||
grid-row: 1 / span 1; | ||
} | ||
|
||
button:focus-visible::after { | ||
content: ''; | ||
position: absolute; | ||
inset: 0px; | ||
cursor: pointer; | ||
border-radius: ${borderRadiusSmall}; | ||
outline: none; | ||
border: 2px solid ${colorStrokeFocus1}; | ||
box-shadow: inset 0 0 0 1px ${colorStrokeFocus2}; | ||
} | ||
|
||
/* --- Disabled attr styles --- */ | ||
|
||
:host([disabled]) .button { | ||
color: ${colorNeutralForegroundDisabled}; | ||
} | ||
:host([disabled]) svg { | ||
filter: invert(89%) sepia(0%) saturate(569%) hue-rotate(155deg) brightness(88%) contrast(87%); | ||
} | ||
|
||
/* --- Expanded attr styles --- */ | ||
|
||
:host([expanded]) .region { | ||
display: block; | ||
} | ||
|
||
:host([expanded]) .default-collapsed-icon, | ||
:host([expanded]) ::slotted([slot='collapsed-icon']), | ||
:host(:not([expanded])) .default-expanded-icon, | ||
:host(:not([expanded])) ::slotted([slot='expanded-icon']), | ||
:host([expanded]) ::slotted([slot='end']), | ||
::slotted([slot='start']), | ||
.region { | ||
display: none; | ||
} | ||
|
||
:host([expanded]) ::slotted([slot='start']), | ||
:host([expanded]) ::slotted([slot='expanded-icon']), | ||
:host(:not([expanded])) ::slotted([slot='collapsed-icon']), | ||
::slotted([slot='end']) { | ||
display: flex; | ||
} | ||
|
||
/* --- Appearance attr styles --- */ | ||
|
||
.heading { | ||
font-size: ${fontSizeBase300}; | ||
line-height: ${lineHeightBase300}; | ||
} | ||
|
||
:host([size='small']) .heading { | ||
font-size: ${fontSizeBase200}; | ||
line-height: ${lineHeightBase200}; | ||
} | ||
|
||
:host([size='large']) .heading { | ||
font-size: ${fontSizeBase400}; | ||
line-height: ${lineHeightBase400}; | ||
} | ||
|
||
:host([size='extra-large']) .heading { | ||
font-size: ${fontSizeBase500}; | ||
line-height: ${lineHeightBase500}; | ||
} | ||
|
||
/* --- expand-icon-position attr styles --- */ | ||
|
||
:host([expand-icon-position='end']) :slotted(span[slot='start']), | ||
:host([expand-icon-position='end']) ::slotted(span[slot='end']) { | ||
grid-column: 1 / span 1; | ||
grid-row: 1; | ||
} | ||
|
||
:host([expand-icon-position='end']) ::slotted(span[slot='start']), | ||
:host([expand-icon-position='end']) ::slotted(span[slot='end']) { | ||
grid-column: 1 / span 1; | ||
grid-row: 1; | ||
} | ||
|
||
:host([expand-icon-position='end']) .icon { | ||
grid-column: 4 / span 1; | ||
grid-row: 1; | ||
display: flex; | ||
padding-left: 10px; | ||
padding-right: 0; | ||
} | ||
|
||
:host([expand-icon-position='end']) .button { | ||
grid-column: 2 / span 3; | ||
grid-row: 1; | ||
} | ||
|
||
/* --- Block attr styles --- */ | ||
|
||
:host([block]) { | ||
max-width: 100%; | ||
} | ||
|
||
:host([expand-icon-position='end']) .heading { | ||
grid-template-columns: auto auto 28px; | ||
} | ||
|
||
:host([expand-icon-position='end']) .icon { | ||
grid-column: 5 / span 1; | ||
} | ||
|
||
:host([block][expand-icon-position='end']) .heading { | ||
grid-template-columns: auto 1fr; | ||
} | ||
|
||
:host([block][expand-icon-position='end']) .icon { | ||
grid-column: 5 / span 1; | ||
} | ||
`; |
40 changes: 40 additions & 0 deletions
40
packages/web-components/src/accordion-item/accordion-item.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ElementViewTemplate, html } from '@microsoft/fast-element'; | ||
import { accordionItemTemplate } from '@microsoft/fast-foundation'; | ||
import { AccordionItem } from './accordion-item.js'; | ||
|
||
const chevronRight20Filled = html.partial(`<svg | ||
width="20" | ||
height="20" | ||
viewBox="0 0 20 20" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="default-collapsed-icon" | ||
> | ||
<path | ||
d="M7.73271 4.20694C8.03263 3.92125 8.50737 3.93279 8.79306 4.23271L13.7944 9.48318C14.0703 9.77285 14.0703 10.2281 13.7944 10.5178L8.79306 15.7682C8.50737 16.0681 8.03263 16.0797 7.73271 15.794C7.43279 15.5083 7.42125 15.0336 7.70694 14.7336L12.2155 10.0005L7.70694 5.26729C7.42125 4.96737 7.43279 4.49264 7.73271 4.20694Z" | ||
fill="#212121" | ||
/> | ||
</svg>`); | ||
|
||
const chevronDown20Filled = html.partial(`<svg | ||
width="20" | ||
height="20" | ||
viewBox="0 0 20 20" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="default-expanded-icon" | ||
> | ||
<path | ||
d="M15.794 7.73271C16.0797 8.03263 16.0681 8.50737 15.7682 8.79306L10.5178 13.7944C10.2281 14.0703 9.77285 14.0703 9.48318 13.7944L4.23271 8.79306C3.93279 8.50737 3.92125 8.03263 4.20694 7.73271C4.49264 7.43279 4.96737 7.42125 5.26729 7.70694L10.0005 12.2155L14.7336 7.70694C15.0336 7.42125 15.5083 7.43279 15.794 7.73271Z" | ||
fill="#212121" | ||
/> | ||
</svg>`); | ||
|
||
/** | ||
* The template for the fluent-accordion component. | ||
* @public | ||
*/ | ||
export const template: ElementViewTemplate<AccordionItem> = accordionItemTemplate({ | ||
collapsedIcon: chevronRight20Filled, | ||
expandedIcon: chevronDown20Filled, | ||
}); |
40 changes: 40 additions & 0 deletions
40
packages/web-components/src/accordion-item/accordion-item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||
import { attr } from '@microsoft/fast-element'; | ||||||
import { FASTAccordionItem } from '@microsoft/fast-foundation'; | ||||||
import { AccordionItemExpandIconPosition, AccordionItemSize } from './accordion-item.options.js'; | ||||||
|
||||||
/** | ||||||
* @internal | ||||||
*/ | ||||||
export class AccordionItem extends FASTAccordionItem { | ||||||
/** | ||||||
* Defines accordion header font size. | ||||||
* | ||||||
* @public | ||||||
* @default 'medium' | ||||||
* @remarks | ||||||
* HTML Attribute: size | ||||||
*/ | ||||||
@attr | ||||||
public size: AccordionItemSize; | ||||||
|
||||||
/** | ||||||
* Sets the width of the focus state. | ||||||
* | ||||||
* @public | ||||||
* @remarks | ||||||
* HTML Attribute: block | ||||||
*/ | ||||||
@attr({ mode: 'boolean' }) | ||||||
public block: boolean = false; | ||||||
|
||||||
/** | ||||||
* Sets expand and collapsed icon position. | ||||||
* | ||||||
* @public | ||||||
* @default 'start' | ||||||
* @remarks | ||||||
* HTML Attribute: expandIconPosition | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
@attr({ attribute: 'expand-icon-position' }) | ||||||
public expandIconPosition: AccordionItemExpandIconPosition; | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { FluentDesignSystem } from '../fluent-design-system.js'; | ||
import { definition } from './accordion-item.definition.js'; | ||
|
||
definition.define(FluentDesignSystem.registry); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './accordion-item.js'; | ||
export * from './accordion-item.options.js'; | ||
export { styles as accordionItemStyles } from './accordion-item.styles.js'; | ||
export { definition as accordionItemDefinition } from './accordion-item.definition.js'; | ||
export { template as accordionItemTemplate } from './accordion-item.template.js'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is start and end in the same grid column?