-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#638 - Changes to make the new Accordion control work in v1
- Loading branch information
Showing
7 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
export * from "./controls/accordion"; |
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,49 @@ | ||
@import "~office-ui-fabric-react/dist/sass/References.scss"; | ||
|
||
.accordion { | ||
background: #fafafa; | ||
|
||
& > button { | ||
min-height: 44px; | ||
border: 2px solid transparent; | ||
outline: 1px solid transparent; | ||
outline-offset: -3px; | ||
background: #f0f0f0; // Microsoft web site doesn't use Fabric colors! | ||
color: rgba(0, 0, 0, 0.8); // Microsoft web site doesn't use Fabric colors! | ||
text-align: left; | ||
width: 100%; | ||
border-bottom: 1px solid rgba(0, 0, 0, 0.2); // Microsoft web site doesn't use Fabric colors! | ||
|
||
:global(.ms-Button-label) { | ||
font-weight: 400; | ||
} | ||
|
||
&:hover, | ||
&:focus { | ||
box-shadow: 0 0 4px 2px rgba(0, 0, 0, 0.16); // Microsoft web site doesn't use Fabric colors! | ||
color: $ms-color-black; | ||
background: #f0f0f0; // Microsoft web site doesn't use Fabric colors! | ||
} | ||
|
||
&:focus { | ||
border-width: 2px; | ||
border-style: solid; | ||
border-color: $ms-color-black; | ||
outline-color: rgba(255, 255, 255, 0.6); // Microsoft web site doesn't use Fabric colors! | ||
} | ||
} | ||
|
||
.drawer { | ||
padding: 24px 12px 24px 12px; | ||
background: #fafafa; // Microsoft web site doesn't use Fabric colors! | ||
font-weight: 400; | ||
font-size: 15px; | ||
line-height: 20px; | ||
} | ||
} | ||
|
||
.accordionChevron { | ||
font-size: 16px; | ||
margin-left: -6px; | ||
color: rgba(0, 0, 0, 0.8); | ||
} |
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,49 @@ | ||
import * as React from 'react'; | ||
import styles from './Accordion.module.scss'; | ||
import { IAccordionProps, IAccordionState } from './index'; | ||
import { css } from "@uifabric/utilities/lib/css"; | ||
import { DefaultButton } from 'office-ui-fabric-react/lib/components/Button'; | ||
import { IIconProps } from 'office-ui-fabric-react/lib/Icon'; | ||
|
||
/** | ||
* Icon styles. Feel free to change them | ||
*/ | ||
const collapsedIcon: IIconProps = { iconName: 'ChevronRight', className: styles.accordionChevron }; | ||
const expandedIcon: IIconProps = { iconName: 'ChevronDown', className: styles.accordionChevron }; | ||
|
||
export class Accordion extends React.Component<IAccordionProps, IAccordionState> { | ||
private _drawerDiv: HTMLDivElement = undefined; | ||
constructor(props: IAccordionProps) { | ||
super(props); | ||
|
||
this.state = { | ||
expanded: props.defaultCollapsed == null ? false : !props.defaultCollapsed | ||
}; | ||
} | ||
|
||
public render(): React.ReactElement<IAccordionProps> { | ||
return ( | ||
<div className={css(styles.accordion, this.props.className)}> | ||
<DefaultButton | ||
toggled={true} | ||
checked={this.state.expanded} | ||
text={this.props.title} | ||
iconProps={this.state.expanded ? expandedIcon : collapsedIcon} | ||
onClick={() => { | ||
this.setState({ | ||
expanded: !this.state.expanded | ||
}); | ||
}} | ||
aria-expanded={this.state.expanded} | ||
aria-controls={this._drawerDiv && this._drawerDiv.id} | ||
/> | ||
{this.state.expanded && | ||
<div className={styles.drawer} ref={(el) => { this._drawerDiv = el; }}> | ||
{this.props.children} | ||
</div> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
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,10 @@ | ||
|
||
export interface IAccordionProps { | ||
defaultCollapsed?: boolean; | ||
title: string; | ||
className?: string; | ||
} | ||
|
||
export interface IAccordionState { | ||
expanded: boolean; | ||
} |
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,2 @@ | ||
export * from './Accordion'; | ||
export * from './IAccordion.types'; |
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
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