This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
886 additions
and
129 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
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
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
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,72 @@ | ||
import styled from 'styled-components' | ||
import { getColor } from '../../styles/utilities/color' | ||
import { rgba } from '../../utilities/color' | ||
|
||
export const CheckMarkCardUI = styled('label')` | ||
box-sizing: border-box; | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
flex-direction: column; | ||
justify-content: center; | ||
width: 100%; | ||
max-width: ${({ maxWidth }) => (maxWidth ? maxWidth : '100px')}; | ||
height: ${({ height }) => (height ? height : 'auto')}; | ||
min-height: 100px; | ||
border: 1px solid ${rgba(getColor('grey.700'), 0.7)}; | ||
border-radius: 4px; | ||
background: white; | ||
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1); | ||
transition: all 0.15s; | ||
will-change: box-shadow, border; | ||
cursor: pointer; | ||
&:hover { | ||
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.1); | ||
transform: translateY(-2px); | ||
} | ||
&.is-checked, | ||
&.is-focused, | ||
&.is-focused.is-checked, | ||
&:focus-within, | ||
&.is-checked:focus-within { | ||
border-color: transparent; | ||
box-shadow: 0px 0px 0 2px ${getColor('blue.500')}; | ||
} | ||
&.is-disabled { | ||
cursor: not-allowed; | ||
opacity: 0.4; | ||
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1); | ||
&:hover { | ||
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1); | ||
transform: translateY(0); | ||
} | ||
} | ||
` | ||
|
||
export const CheckMarkUI = styled('div')` | ||
position: absolute; | ||
top: -2px; | ||
left: -2px; | ||
height: 28px; | ||
width: 28px; | ||
border-radius: 4px 0px 5px; | ||
background: ${getColor('blue.500')}; | ||
opacity: 0; | ||
transition: opacity 0.15s; | ||
will-change: opacity; | ||
.is-checked & { | ||
opacity: 1; | ||
} | ||
.checkmark-icon { | ||
color: white; | ||
position: absolute; | ||
top: calc(50% - 13px); | ||
left: calc(50% - 13px); | ||
} | ||
` |
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,162 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { classNames } from '../../utilities/classNames' | ||
import { createUniqueIDFactory } from '../../utilities/id' | ||
import { noop } from '../../utilities/other' | ||
import Icon from '../Icon' | ||
import Checkbox from '../Checkbox' | ||
import VisuallyHidden from '../VisuallyHidden' | ||
import { CheckMarkCardUI, CheckMarkUI } from './CheckMarkCard.css' | ||
|
||
const uniqueID = createUniqueIDFactory('CheckMarkCard') | ||
|
||
export class CheckMarkCard extends React.Component { | ||
constructor(props) { | ||
super(props) | ||
|
||
this.state = { | ||
id: props.id || uniqueID(), | ||
} | ||
|
||
this.checkMarkCardRef = React.createRef() | ||
} | ||
|
||
componentDidMount() { | ||
if (this.props.isFocused && this.inputNode) { | ||
this.checkMarkCardRef.current.classList.add('is-focused') | ||
this.inputNode.focus() | ||
} | ||
} | ||
|
||
getClassName() { | ||
const { className, checked, disabled } = this.props | ||
|
||
return classNames( | ||
'c-CheckMarkCard', | ||
className, | ||
checked && 'is-checked', | ||
disabled && 'is-disabled' | ||
) | ||
} | ||
|
||
setInputNodeRef = node => { | ||
this.inputNode = node | ||
this.props.inputRef(node) | ||
} | ||
|
||
handleOnChange = (value, checked) => { | ||
if (checked) { | ||
this.checkMarkCardRef.current.classList.add('is-checked') | ||
} else { | ||
this.checkMarkCardRef.current.classList.remove('is-checked') | ||
} | ||
|
||
this.props.onChange(value, checked) | ||
} | ||
|
||
handleOnBlur = event => { | ||
this.checkMarkCardRef.current.classList.remove('is-focused') | ||
this.props.onBlur(event) | ||
} | ||
|
||
handleOnFocus = event => { | ||
this.checkMarkCardRef.current.classList.add('is-focused') | ||
this.props.onFocus(event) | ||
} | ||
|
||
render() { | ||
const { | ||
checked, | ||
children, | ||
disabled, | ||
label, | ||
maxWidth, | ||
height, | ||
value, | ||
...rest | ||
} = this.props | ||
const { id } = this.state | ||
|
||
return ( | ||
<CheckMarkCardUI | ||
{...rest} | ||
className={this.getClassName()} | ||
htmlFor={id} | ||
maxWidth={maxWidth} | ||
height={height} | ||
ref={this.checkMarkCardRef} | ||
> | ||
<CheckMarkUI> | ||
<Icon className="checkmark-icon" name="checkmark" size="24" /> | ||
</CheckMarkUI> | ||
<VisuallyHidden> | ||
<Checkbox | ||
checked={checked} | ||
disabled={disabled} | ||
id={id} | ||
inputRef={this.setInputNodeRef} | ||
label={label || value} | ||
onBlur={this.handleOnBlur} | ||
onFocus={this.handleOnFocus} | ||
onChange={this.handleOnChange} | ||
value={value} | ||
/> | ||
</VisuallyHidden> | ||
{children} | ||
</CheckMarkCardUI> | ||
) | ||
} | ||
} | ||
|
||
CheckMarkCard.defaultProps = { | ||
checked: false, | ||
'data-cy': 'CheckMarkCard', | ||
inputRef: noop, | ||
isFocused: false, | ||
onBlur: noop, | ||
onChange: noop, | ||
onFocus: noop, | ||
} | ||
|
||
CheckMarkCard.propTypes = { | ||
/** Custom class names to be added to the component. */ | ||
className: PropTypes.string, | ||
/** Determines if the card is checked. */ | ||
checked: PropTypes.bool, | ||
/** Data attr for Cypress tests. */ | ||
'data-cy': PropTypes.string, | ||
/** Determines if the card is disabled. */ | ||
disabled: PropTypes.bool, | ||
/** ID for the input. */ | ||
id: PropTypes.string, | ||
/** Callback to obtain the <input> node. */ | ||
inputRef: PropTypes.func, | ||
/** Whether the card should be focused */ | ||
isFocused: PropTypes.bool, | ||
/** Set the height of the Card. */ | ||
height: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number, | ||
PropTypes.func, | ||
]), | ||
/** Set the max width of the Card. */ | ||
maxWidth: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number, | ||
PropTypes.func, | ||
]), | ||
/** Callback when the input is blurred. */ | ||
onBlur: PropTypes.func, | ||
/** Callback when the input value is changed. */ | ||
onChange: PropTypes.func, | ||
/** Callback when the input is focused. */ | ||
onFocus: PropTypes.func, | ||
/** The value of the input. */ | ||
value: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number, | ||
PropTypes.bool, | ||
]), | ||
} | ||
|
||
export default CheckMarkCard |
Oops, something went wrong.