This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MenuItem|AccordionTitle): add ability for removing and customizi…
…ng the (active|submenu) indicator (#721) * -added option for hiding the submenu indicators as well as shorthands for the vertical and horizontal menus -TODO rethink the names used * -refactored menu item styles * -added rotate prop to the Icon -supporting rtl for the icons -added submenu and active indicators in the Menu and AccordionTitle components * -removed boolean from the types of the indicators * -added UnicodeCharacter component * -replaced style unicode characters with UnicodeCharacter usages * -fixed tests * -replaced UnicodeCharacter with Indicator * -renamed indicator* props to indicator -refactored icon styles to be more readable * -removed color prop in the indicator -added examples * -renamed forward and back direction to start and end -moved the rotate icon prop from default to override props in the Indicator component * -updated changelog * -remove default props in AccordionTitle * -removed arrow unicode chars from the teams theme -remove helper methods for getting the mapping arrow in rtl * -addressed comments on the PR * -replaced div with fragment
- Loading branch information
Showing
18 changed files
with
229 additions
and
59 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
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Indicator/Types/IndicatorExample.shorthand.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,6 @@ | ||
import * as React from 'react' | ||
import { Indicator } from '@stardust-ui/react' | ||
|
||
const IndicatorExample = () => <Indicator /> | ||
|
||
export default IndicatorExample |
11 changes: 11 additions & 0 deletions
11
docs/src/examples/components/Indicator/Types/IndicatorExampleDirection.shorthand.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,11 @@ | ||
import * as React from 'react' | ||
import { Indicator } from '@stardust-ui/react' | ||
|
||
const IndicatorExampleDirection = () => ( | ||
<> | ||
<Indicator direction="end" /> <Indicator direction="bottom" /> <Indicator direction="start" />{' '} | ||
<Indicator direction="top" />{' '} | ||
</> | ||
) | ||
|
||
export default IndicatorExampleDirection |
12 changes: 12 additions & 0 deletions
12
docs/src/examples/components/Indicator/Types/IndicatorExampleIcon.shorthand.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,12 @@ | ||
import * as React from 'react' | ||
import { Indicator } from '@stardust-ui/react' | ||
|
||
const IndicatorExampleIcon = () => ( | ||
<> | ||
<Indicator icon="chevron down" direction="end" />{' '} | ||
<Indicator icon="chevron down" direction="bottom" />{' '} | ||
<Indicator icon="chevron down" direction="start" />{' '} | ||
<Indicator icon="chevron down" direction="top" />{' '} | ||
</> | ||
) | ||
export default IndicatorExampleIcon |
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,25 @@ | ||
import * as React from 'react' | ||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
||
const Types = () => ( | ||
<ExampleSection title="Types"> | ||
<ComponentExample | ||
title="Default" | ||
description="A default Indicator ." | ||
examplePath="components/Indicator/Types/IndicatorExample" | ||
/> | ||
<ComponentExample | ||
title="Direction" | ||
description="An Indicator may show towards different direction." | ||
examplePath="components/Indicator/Types/IndicatorExampleDirection" | ||
/> | ||
<ComponentExample | ||
title="Icon" | ||
description="An Indicator may show icon instead of character." | ||
examplePath="components/Indicator/Types/IndicatorExampleIcon" | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as React from 'react' | ||
import Types from './Types' | ||
|
||
const IndicatorExamples = () => ( | ||
<> | ||
<Types /> | ||
</> | ||
) | ||
|
||
export default IndicatorExamples |
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
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,79 @@ | ||
import * as React from 'react' | ||
import * as PropTypes from 'prop-types' | ||
|
||
import { | ||
createShorthandFactory, | ||
UIComponent, | ||
UIComponentProps, | ||
commonPropTypes, | ||
customPropTypes, | ||
} from '../../lib' | ||
import { ReactProps, ShorthandValue } from '../../../types/utils' | ||
import Icon from '../Icon/Icon' | ||
|
||
export interface IndicatorProps extends UIComponentProps { | ||
/** The indicator can point towards different directions. */ | ||
direction?: 'start' | 'end' | 'top' | 'bottom' | ||
|
||
/** The indicator can show specific icon if provided. */ | ||
icon?: ShorthandValue | ||
} | ||
|
||
/** | ||
* An indicator is suggesting additional content next to the element it is used in. | ||
*/ | ||
class Indicator extends UIComponent<ReactProps<IndicatorProps>, any> { | ||
static displayName = 'Indicator' | ||
|
||
static create: Function | ||
|
||
static className = 'ui-indicator' | ||
|
||
static directionMap = { | ||
end: { unicode: '\u25B8', rotation: -90 }, | ||
start: { unicode: '\u25C2', rotation: 90 }, | ||
top: { unicode: '\u25B4', rotation: 180 }, | ||
bottom: { unicode: '\u25BE', rotation: 0 }, | ||
} | ||
|
||
static propTypes = { | ||
...commonPropTypes.createCommon({ children: false, content: false }), | ||
direction: PropTypes.oneOf(['start', 'end', 'top', 'bottom']), | ||
icon: customPropTypes.itemShorthand, | ||
} | ||
|
||
static defaultProps = { | ||
as: 'span', | ||
direction: 'bottom', | ||
} | ||
|
||
renderComponent({ ElementType, classes, unhandledProps, rtl }) { | ||
const { direction, icon, color } = this.props | ||
const hexUnicode = | ||
direction && Indicator.directionMap[this.getDirectionBasedOnRtl(rtl, direction)].unicode | ||
|
||
return ( | ||
<ElementType {...unhandledProps} className={classes.root}> | ||
{icon | ||
? Icon.create(icon, { | ||
defaultProps: { color }, | ||
overrideProps: ({ rotate }) => ({ | ||
rotate: (Indicator.directionMap[direction].rotation || 0) + (rotate || 0), | ||
}), | ||
}) | ||
: hexUnicode} | ||
</ElementType> | ||
) | ||
} | ||
|
||
private getDirectionBasedOnRtl = (rtl: boolean, direction) => { | ||
if (!rtl) return direction | ||
if (direction === 'start') return 'end' | ||
if (direction === 'end') return 'start' | ||
return direction | ||
} | ||
} | ||
|
||
Indicator.create = createShorthandFactory(Indicator, 'hex') | ||
|
||
export default Indicator |
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
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
27 changes: 9 additions & 18 deletions
27
src/themes/teams/components/Accordion/accordionTitleStyles.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 |
---|---|---|
@@ -1,22 +1,13 @@ | ||
import { ICSSInJSStyle } from '../../../types' | ||
import { getSideArrow } from '../../utils' | ||
|
||
const accordionTitleStyles = { | ||
root: ({ props, theme }): ICSSInJSStyle => { | ||
const { active } = props | ||
const { arrowDown } = theme.siteVariables | ||
const sideArrow = getSideArrow(theme) | ||
return { | ||
display: 'inline-block', | ||
verticalAlign: 'middle', | ||
padding: '.5rem 0', | ||
cursor: 'pointer', | ||
'::before': { | ||
userSelect: 'none', | ||
content: active ? `"${arrowDown}"` : `"${sideArrow}"`, | ||
}, | ||
} | ||
}, | ||
root: () => ({ | ||
display: 'inline-block', | ||
verticalAlign: 'middle', | ||
padding: '.5rem 0', | ||
cursor: 'pointer', | ||
}), | ||
indicator: () => ({ | ||
userSelect: 'none', | ||
}), | ||
} | ||
|
||
export default accordionTitleStyles |
Oops, something went wrong.