-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Classifier: Clean up TaskInput styling (#6532)
* Refactor styling of TaskInput and its components * Remove enzyme from InputStatus.spec
- Loading branch information
1 parent
57c52de
commit 3e8f2ee
Showing
10 changed files
with
103 additions
and
103 deletions.
There are no files selected for viewing
21 changes: 5 additions & 16 deletions
21
packages/lib-classifier/src/plugins/tasks/components/InputIcon/InputIcon.js
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,42 +1,31 @@ | ||
import PropTypes from 'prop-types' | ||
import { node, string } from 'prop-types' | ||
import styled, { css } from 'styled-components' | ||
|
||
export const StyledInputIcon = styled.span` | ||
${props => props.color && css`color: ${props.color};`} | ||
background-color: #2D2D2D; | ||
display: flex; | ||
align-items: center; | ||
padding-left: 15px; | ||
&::after { | ||
content: " "; | ||
margin-right: 1ch; | ||
white-space: pre; | ||
} | ||
padding: 15px; | ||
> svg { | ||
fill-opacity: 0.1; | ||
height: 1.5em; | ||
stroke: currentColor; | ||
stroke-width: 5; | ||
vertical-align: bottom; | ||
width: 1.5em; | ||
} | ||
` | ||
|
||
export default function InputIcon ({ color, icon }) { | ||
export default function InputIcon ({ color = 'white', icon }) { | ||
return ( | ||
<StyledInputIcon color={color}> | ||
{icon} | ||
</StyledInputIcon> | ||
) | ||
} | ||
|
||
InputIcon.defaultProps = { | ||
color: 'white' | ||
} | ||
|
||
InputIcon.propTypes = { | ||
color: PropTypes.string, | ||
icon: PropTypes.node.isRequired | ||
color: string, | ||
icon: node.isRequired | ||
} |
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
31 changes: 11 additions & 20 deletions
31
packages/lib-classifier/src/plugins/tasks/components/InputStatus/InputStatus.spec.js
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,35 +1,26 @@ | ||
import { shallow } from 'enzyme' | ||
import InputStatus, { StyledInputStatus } from './InputStatus' | ||
import { render, screen } from '@testing-library/react' | ||
import InputStatus from './InputStatus' | ||
|
||
/** The translation function will simply return keys in a testing env */ | ||
|
||
describe('InputStatus', function () { | ||
it('should render without crashing', function () { | ||
const wrapper = shallow(<InputStatus />) | ||
expect(wrapper).to.be.ok() | ||
}) | ||
|
||
it('should render a StyledInputStatus component', function () { | ||
const wrapper = shallow(<InputStatus />) | ||
expect(wrapper.find(StyledInputStatus)).to.have.lengthOf(1) | ||
}) | ||
|
||
it('should not render any requirements if props.tool.min or props.tool.max is not defined', function () { | ||
const wrapper = shallow(<InputStatus />) | ||
expect(wrapper.contains('InputStatus.drawn')).to.be.true() | ||
render(<InputStatus />) | ||
expect(screen.getByText('InputStatus.drawn')).to.be.ok() | ||
}) | ||
|
||
it('should render minimum drawing requirements if props.tool.min is defined', function () { | ||
const wrapper = shallow(<InputStatus tool={{ min: 1 }} />) | ||
expect(wrapper.contains('InputStatus.min')).to.be.true() | ||
render(<InputStatus tool={{ min: 1 }} />) | ||
expect(screen.getByText('InputStatus.min')).to.be.ok() | ||
}) | ||
|
||
it('should render maxmimum drawing requirements if props.tool.max is defined', function () { | ||
const wrapper = shallow(<InputStatus tool={{ max: 2 }} />) | ||
expect(wrapper.contains('InputStatus.max')).to.be.true() | ||
render(<InputStatus tool={{ max: 2 }} />) | ||
expect(screen.getByText('InputStatus.max')).to.be.ok() | ||
}) | ||
|
||
it('should render minimum and maxmimum drawing requirements if props.tool.min and props.tool.max are defined', function () { | ||
const wrapper = shallow(<InputStatus tool={{ min: 1, max: 2 }} />) | ||
expect(wrapper.contains('InputStatus.maxAndMin')).to.be.true() | ||
render(<InputStatus tool={{ min: 1, max: 2 }} />) | ||
expect(screen.getByText('InputStatus.maxAndMin')).to.be.ok() | ||
}) | ||
}) |
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
50 changes: 50 additions & 0 deletions
50
packages/lib-classifier/src/plugins/tasks/components/TaskInput/TaskInput.stories.js
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,50 @@ | ||
import { Edit } from 'grommet-icons' | ||
|
||
import TaskInput from './TaskInput' | ||
import InputStatus from '../InputStatus/InputStatus.js' | ||
|
||
export default { | ||
title: 'Tasks / TaskInput', | ||
component: TaskInput, | ||
args: { | ||
checked: true | ||
} | ||
} | ||
|
||
export const Default = {} | ||
|
||
Default.args = { | ||
label: 'Label', | ||
index: 0, | ||
name: 'default', | ||
type: 'radio' | ||
} | ||
|
||
export const CustomIcon = {} | ||
|
||
CustomIcon.args = { | ||
label: 'Drawing a point', | ||
labelIcon: <Edit color='gold' />, | ||
index: 0, | ||
name: 'custom-icon', | ||
type: 'radio' | ||
} | ||
|
||
export const ImageAndTextLabel = {} | ||
|
||
ImageAndTextLabel.args = { | ||
label: '![alt](https://thumbnails.zooniverse.org/60x/panoptes-uploads.zooniverse.org/production/project_attached_image/1ec52a74-9e49-4579-91ff-0140eb5371e6.png) Galaxies', | ||
index: 0, | ||
name: 'markdownz', | ||
type: 'checkbox' | ||
} | ||
|
||
export const WithLabelStatus = {} | ||
|
||
WithLabelStatus.args = { | ||
index: 0, | ||
label: 'Do the task', | ||
labelStatus: <InputStatus count={3} />, | ||
name: 'drawing', | ||
type: 'radio' | ||
} |
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
4 changes: 0 additions & 4 deletions
4
.../lib-classifier/src/plugins/tasks/components/TaskInput/helpers/doesTheLabelHaveAnImage.js
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
packages/lib-classifier/src/plugins/tasks/components/TaskInput/helpers/index.js
This file was deleted.
Oops, something went wrong.
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