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
feat(MenuItem|AccordionTitle): add ability for removing and customizing the (active|submenu) indicator #721
Merged
+229
−59
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fe22c57
-added option for hiding the submenu indicators as well as shorthands…
6b3a2e1
-refactored menu item styles
740e44f
-added rotate prop to the Icon
0d1f9fb
-removed boolean from the types of the indicators
8e7c437
-added UnicodeCharacter component
48eca8b
-replaced style unicode characters with UnicodeCharacter usages
00738b4
-fixed tests
55ec1bd
-replaced UnicodeCharacter with Indicator
a20f12b
-renamed indicator* props to indicator
670ee76
-removed color prop in the indicator
4c7cbd9
-renamed forward and back direction to start and end
a4a58ac
Merge branch 'master' into feat/menu-item-hide-submenu-indicator
1073c5e
-updated changelog
3b481f7
-remove default props in AccordionTitle
ad4040a
-removed arrow unicode chars from the teams theme
7c445c2
Merge branch 'master' into feat/menu-item-hide-submenu-indicator
048bc08
-addressed comments on the PR
2426e20
-replaced div with fragment
4c2fd8b
Merge branch 'master' into feat/menu-item-hide-submenu-indicator
mnajdova 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
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.
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.
String looks like a valid value, too:
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.
The rotate property of the icon can be used for calculation as well, take a look in the Indicator component (the overrideProps function for the Icon). In that case we will need to cast this to number if it was provided as string. Do we really want this?