@navinc/base-react-components
Version:
Nav's Pattern Library
63 lines (51 loc) • 1.74 kB
JavaScript
import styled from 'styled-components'
import CarrotLeft from './icons/actions/carrot-left.js'
import PropTypes from 'prop-types'
import isRebrand from './is-rebrand.js'
const setColor = ({ isInvalid, disabled, theme }) => {
if (isRebrand(theme)) {
if (isInvalid) return theme.navStatusNegative
return disabled ? theme.navNeutral400 : theme.navPrimary
}
if (isInvalid) return theme.error
return disabled ? theme.scuttleGray500 : theme.azure
}
const ChevronWrapper = styled.div`
pointer-events: none;
`
const StyledChevron = styled(CarrotLeft)`
fill: ${({ isInvalid, disabled, theme }) => setColor({ isInvalid, disabled, theme })};
transform: ${({ $isOpen }) => `rotate(${$isOpen ? '0turn' : '-0.25turn'})}`};
transition: 'transform 0.2s ease-in-out',
transitionDelay: '0.1s',
willChange: 'transform',
`
ChevronWrapper.displayName = 'ChevronWrapper'
/**
*
* @param {*} props You can not access props directly. | optional | {}
* @property {string} className
* @property {boolean} disabled
* @property {boolean} isInvalid
* @property {boolean} $isOpen
* @returns React.ReactElement
*/
export const Chevron = ({ className, disabled, isInvalid, $isOpen }) => (
<ChevronWrapper className={className}>
<StyledChevron $isOpen={$isOpen} disabled={disabled} isInvalid={isInvalid} />
</ChevronWrapper>
)
Chevron.propTypes = {
className: PropTypes.string,
disabled: PropTypes.bool,
isInvalid: PropTypes.bool,
/** Shares the isOpen state with styled-components, but does not pass down to the child as a prop */
$isOpen: PropTypes.bool,
}
Chevron.defaultProps = {
disabled: false,
isInvalid: false,
$isOpen: false,
}
Chevron.displayName = 'Chevron'
export default styled(Chevron)``