-
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
Changes from 8 commits
fe22c57
6b3a2e1
740e44f
0d1f9fb
8e7c437
48eca8b
00738b4
55ec1bd
a20f12b
670ee76
4c7cbd9
a4a58ac
1073c5e
3b481f7
ad4040a
7c445c2
048bc08
2426e20
4c2fd8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import * as React from 'react' | ||
import * as PropTypes from 'prop-types' | ||
|
||
import { | ||
createShorthandFactory, | ||
UIComponent, | ||
UIComponentProps, | ||
commonPropTypes, | ||
ColorComponentProps, | ||
customPropTypes, | ||
} from '../../lib' | ||
import { ReactProps, ShorthandValue } from '../../../types/utils' | ||
import Icon from '../Icon/Icon' | ||
|
||
export interface IndicatorProps extends UIComponentProps, ColorComponentProps { | ||
/** The indicator can be direction in different directions. */ | ||
direction?: 'forward' | 'back' | 'top' | 'bottom' | ||
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. For me, it seems a bit confusable, what is 'bottom' and what is 'back'. I guess it's left but seems not very intuitive. 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.
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. Would like to avoid the right and left, as in rtl it won't make sense to use them.. I am open to other suggestion. This one were gathered from the browser arrows for navigation (back and forward). Maybe start and end? What do you think? 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. Well, we use 'right' and 'left' for the Popup too. 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. I vote for 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. @miroslavstastny agree, let's strive for consistency, although it seems really strange for me to have the '<' indicator a start, and '>' as end.. We can change it later anyway... |
||
|
||
/** The indicator can show specific icon if provided. */ | ||
icon?: ShorthandValue | ||
} | ||
|
||
/** | ||
* An indicator is suggest additional content next to the element it is inside. | ||
*/ | ||
class Indicator extends UIComponent<ReactProps<IndicatorProps>, any> { | ||
static displayName = 'Indicator' | ||
|
||
static create: Function | ||
|
||
static className = 'ui-indicator' | ||
|
||
static directionMap = { | ||
forward: { unicode: '25B8', rotation: -90 }, | ||
back: { unicode: '25C2', rotation: 90 }, | ||
top: { unicode: '25B4', rotation: 180 }, | ||
bottom: { unicode: '25BE', rotation: 0 }, | ||
} | ||
|
||
static propTypes = { | ||
...commonPropTypes.createCommon({ children: false, content: false }), | ||
direction: PropTypes.oneOf(['forward', 'back', '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 | ||
const contentProps = !icon | ||
? { | ||
dangerouslySetInnerHTML: { | ||
__html: hexUnicode && this.isHex(hexUnicode) ? `&#x${hexUnicode};` : '', | ||
}, | ||
} | ||
mnajdova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: { | ||
children: Icon.create(icon, { | ||
defaultProps: { color, rotate: Indicator.directionMap[direction].rotation }, | ||
mnajdova marked this conversation as resolved.
Show resolved
Hide resolved
sophieH29 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}), | ||
} | ||
return <ElementType {...unhandledProps} className={classes.root} {...contentProps} /> | ||
} | ||
|
||
private isHex(h) { | ||
return ( | ||
parseInt(h, 16) | ||
.toString(16) | ||
.toUpperCase() === h.toUpperCase() | ||
) | ||
} | ||
|
||
private getDirectionBasedOnRtl = (rtl: boolean, direction) => { | ||
if (!rtl) return direction | ||
if (direction === 'forward') return 'back' | ||
if (direction === 'back') return 'forward' | ||
return direction | ||
} | ||
} | ||
|
||
Indicator.create = createShorthandFactory(Indicator, 'hex') | ||
|
||
export default Indicator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as Loader } from './components/Loader/loaderStyles' | ||
export { default as Text } from './components/Text/textStyles' | ||
export { default as Indicator } from './components/Indicator/indicatorStyles' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as Loader } from './components/Loader/loaderVariables' | ||
export { default as Text } from './components/Text/textVariables' | ||
export { default as UnicodeCharacter } from './components/Indicator/indicatorVariables' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as _ from 'lodash' | ||
import { ComponentStyleFunctionParam, ICSSInJSStyle } from '../../../types' | ||
import { IndicatorVariables } from './indicatorVariables' | ||
import { IndicatorProps } from '@stardust-ui/react' | ||
|
||
export default { | ||
root: ({ | ||
props: { color }, | ||
mnajdova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
variables: v, | ||
}: ComponentStyleFunctionParam<IndicatorProps, IndicatorVariables>): ICSSInJSStyle => { | ||
return { | ||
...(color && { color: _.get(v.colors, color) }), | ||
} | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ColorValues } from '../../../types' | ||
import { mapColorsToScheme } from '../../../../lib' | ||
|
||
export interface IndicatorVariables { | ||
colors: ColorValues<string> | ||
} | ||
|
||
export default (siteVariables): IndicatorVariables => { | ||
const colorVariant = 500 | ||
|
||
return { | ||
colors: mapColorsToScheme(siteVariables, colorVariant), | ||
} | ||
} |
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', | ||
}), | ||
activeIndicator: () => ({ | ||
userSelect: 'none', | ||
}), | ||
} | ||
|
||
export default accordionTitleStyles |
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?