-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(html): add expansion-panel helper
- Loading branch information
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
packages/html/src/expansion-panel/expansion-panel.spec.tsx
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,86 @@ | ||
import * as React from 'react'; | ||
import { classNames, stateClassNames, States } from '../utils'; | ||
import { Icon } from '../icon'; | ||
|
||
const EXPANSION_PANEL_CLASSNAME = 'k-expander'; | ||
|
||
const states = [ | ||
States.hover, | ||
States.focus, | ||
States.disabled, | ||
]; | ||
|
||
const options = {}; | ||
|
||
export type KendoExpansionPanelProps = { | ||
title?: string; | ||
subtitle?: string; | ||
expanded?: boolean; | ||
dir?: 'ltr' | 'rtl'; | ||
contentStyle?: React.CSSProperties; | ||
}; | ||
|
||
export type KendoExpansionPanelState = { [K in (typeof states)[number]]?: boolean }; | ||
|
||
const defaultProps = {}; | ||
|
||
export const ExpansionPanel = ( | ||
props: KendoExpansionPanelProps & | ||
KendoExpansionPanelState & | ||
React.HTMLAttributes<HTMLDivElement> | ||
) => { | ||
const { | ||
title, | ||
subtitle, | ||
expanded, | ||
hover, | ||
focus, | ||
disabled, | ||
dir, | ||
contentStyle | ||
} = props; | ||
|
||
return ( | ||
<div className={classNames( | ||
props.className, | ||
EXPANSION_PANEL_CLASSNAME, | ||
stateClassNames(EXPANSION_PANEL_CLASSNAME, { | ||
hover, | ||
focus, | ||
disabled | ||
}), | ||
{ | ||
'k-expanded': expanded, | ||
} | ||
)} dir={dir}> | ||
<div className={classNames( | ||
'k-expander-header', | ||
stateClassNames(EXPANSION_PANEL_CLASSNAME, { | ||
hover | ||
}) | ||
)}> | ||
<div className="k-expander-title">{title}</div> | ||
<span className="k-spacer"></span> | ||
<div className="k-expander-sub-title">{subtitle}</div> | ||
<span className="k-expander-indicator"> | ||
{ !expanded ? <Icon name="chevron-down" /> : <Icon name="chevron-up" /> } | ||
</span> | ||
</div> | ||
<div className={classNames( | ||
'k-expander-content-wrapper', | ||
{ | ||
'k-d-none': !expanded | ||
} | ||
)}> | ||
<div className="k-expander-content" style={contentStyle}> | ||
{props.children} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
ExpansionPanel.states = states; | ||
ExpansionPanel.options = options; | ||
ExpansionPanel.className = EXPANSION_PANEL_CLASSNAME; | ||
ExpansionPanel.defaultProps = defaultProps; |
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 './expansion-panel.spec'; |
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