Skip to content

Commit f0b57a6

Browse files
author
Sarah Allen
committed
Fix renamings. Support setting pad on Modal body. Use CSS grid correctly
1 parent 016552e commit f0b57a6

File tree

13 files changed

+122
-97
lines changed

13 files changed

+122
-97
lines changed

packages/lib-classifier/src/components/Classifier/components/FieldGuide/FieldGuideContainer.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FieldGuideContainer extends React.Component {
3636
<Modal
3737
active={showModal}
3838
closeFn={this.onClose.bind(this)}
39+
pad='small'
3940
title={counterpart('FieldGuide.title')}
4041
>
4142
<FieldGuide />

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/FieldGuide.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import { Box } from 'grommet'
22
import React from 'react'
33
import PropTypes from 'prop-types'
4-
import styled from 'styled-components'
4+
import { ResponsiveContext } from 'grommet'
55
import { inject, observer } from 'mobx-react'
66
import FieldGuideItems from './components/FieldGuideItems'
77
import FieldGuideItem from './components/FieldGuideItem'
88

9-
const StyledBox = styled(Box)`
10-
max-height: 415px;
11-
max-width: 490px;
12-
overflow: auto;
13-
`
14-
15-
169
function storeMapper(stores) {
17-
const { active: fieldGuide, activeItem } = stores.classifierStore.fieldGuide
10+
const { active: fieldGuide, activeItemIndex } = stores.classifierStore.fieldGuide
1811
return {
19-
activeItem,
12+
activeItemIndex,
2013
items: fieldGuide.items
2114
}
2215
}
@@ -25,24 +18,30 @@ function storeMapper(stores) {
2518
@observer
2619
class FieldGuide extends React.Component {
2720
render () {
28-
const { activeItem, className, items } = this.props
21+
const { activeItemIndex, className, items } = this.props
2922
return (
30-
<StyledBox className={className}>
31-
{items[activeItem] ?
32-
<FieldGuideItem item={items[activeItem]} /> :
33-
<FieldGuideItems items={items} />}
34-
</StyledBox>
23+
<ResponsiveContext.Consumer>
24+
{size => {
25+
const height = (size === 'small') ? '100%' : '415px'
26+
const width = (size === 'small') ? '100%' : '490px'
27+
return (
28+
<Box className={className} height={height} overflow='auto' width={width}>
29+
{items[activeItemIndex] ?
30+
<FieldGuideItem item={items[activeItemIndex]} /> :
31+
<FieldGuideItems items={items} />}
32+
</Box>)}}
33+
</ResponsiveContext.Consumer>
3534
)
3635
}
3736
}
3837

3938
FieldGuide.wrappedComponent.defaultProps = {
40-
activeItem: -1,
39+
activeItemIndex: -1,
4140
className: '',
4241
}
4342

4443
FieldGuide.wrappedComponent.propTypes = {
45-
activeItem: PropTypes.number,
44+
activeItemIndex: PropTypes.number,
4645
className: PropTypes.string,
4746
items: PropTypes.arrayOf(PropTypes.object).isRequired
4847
}

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItem/FieldGuideItem.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,63 @@ import { Button, Box } from 'grommet'
22
import { FormPrevious } from 'grommet-icons'
33
import styled from 'styled-components'
44
import React from 'react'
5-
import { Markdownz, Media } from '@zooniverse/react-components'
5+
import { Markdownz } from '@zooniverse/react-components'
6+
import zooTheme from '@zooniverse/grommet-theme'
67
import PropTypes from 'prop-types'
78
import { observable } from 'mobx'
89
import { inject, observer, PropTypes as MobXPropTypes } from 'mobx-react'
10+
import FieldGuideItemIcon from '../FieldGuideItemIcon'
911
import counterpart from 'counterpart'
1012
import en from './locales/en'
1113

1214
counterpart.registerTranslations('en', en)
1315

16+
const StyledButton = styled(Button)`
17+
padding: 0;
18+
19+
&:hover > svg, &:focus > svg {
20+
fill: ${zooTheme.global.colors['dark-5']};
21+
stroke: ${zooTheme.global.colors['dark-5']};
22+
}
23+
`
24+
1425
const FieldGuideItemHeader = styled(Box)`
1526
> h3 {
1627
margin: 0;
1728
}
1829
`
1930

2031
function storeMapper(stores) {
21-
const { setActiveItem, attachedMedia: icons } = stores.classifierStore.fieldGuide
32+
const { setActiveItemIndex, attachedMedia: icons } = stores.classifierStore.fieldGuide
2233
return {
2334
icons,
24-
setActiveItem
35+
setActiveItemIndex
2536
}
2637
}
2738

2839
@inject(storeMapper)
2940
@observer
3041
class FieldGuideItem extends React.Component {
3142
render () {
32-
const { className, icons, item, setActiveItem } = this.props
43+
const { className, icons, item, setActiveItemIndex } = this.props
3344
const icon = icons.get(item.icon)
3445

3546
return (
3647
<Box className={className}>
37-
<FieldGuideItemHeader align='center' direction='row'>
38-
<Button
48+
<FieldGuideItemHeader align='center' direction='row' margin={{ bottom: 'small' }}>
49+
<StyledButton
3950
a11yTitle={counterpart("FieldGuideItem.ariaTitle")}
40-
icon={<FormPrevious />}
41-
onClick={() => setActiveItem()}
51+
icon={<FormPrevious color='light-5' />}
52+
margin={{ right: 'small' }}
53+
onClick={() => setActiveItemIndex()}
4254
plain
4355
/>
4456
<Markdownz>
4557
{`### ${item.title}`}
4658
</Markdownz>
4759
</FieldGuideItemHeader>
4860
<Box direction='column'>
49-
{icon && Object.keys(icon).length > 0 &&
50-
<Media fit='contain' height={140} src={icon.src} />}
61+
<FieldGuideItemIcon icon={icon} height='140' viewBox='0 0 200 100' />
5162
<Markdownz>
5263
{item.content}
5364
</Markdownz>
@@ -66,7 +77,7 @@ FieldGuideItem.wrappedComponent.propTypes = {
6677
className: PropTypes.string,
6778
icons: MobXPropTypes.observableMap,
6879
item: PropTypes.object.isRequired,
69-
setActiveItem: PropTypes.func.isRequired
80+
setActiveItemIndex: PropTypes.func.isRequired
7081
}
7182

7283
export default FieldGuideItem

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItem/FieldGuideItem.spec.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,29 @@ describe('Component > FieldGuideItem', function () {
2222
<FieldGuideItem.wrappedComponent
2323
icons={attachedMedia}
2424
item={item}
25-
setActiveItem={() => { }}
25+
setActiveItemIndex={() => { }}
2626
/>)
2727
expect(wrapper).to.be.ok
2828
})
2929

30-
it('should call setActiveItem when the previous button is clicked', function () {
31-
const setActiveItemSpy = sinon.spy()
30+
it('should call setActiveItemIndex when the previous button is clicked', function () {
31+
const setActiveItemIndexSpy = sinon.spy()
3232
const wrapper = mount(
3333
<FieldGuideItem.wrappedComponent
3434
icons={attachedMedia}
3535
item={item}
36-
setActiveItem={setActiveItemSpy}
36+
setActiveItemIndex={setActiveItemIndexSpy}
3737
/>)
3838
wrapper.find(Button).simulate('click')
39-
expect(setActiveItemSpy).to.have.been.calledOnceWith()
39+
expect(setActiveItemIndexSpy).to.have.been.calledOnceWith()
4040
})
4141

4242
it('should render the item title as markdown', function () {
4343
const wrapper = shallow(
4444
<FieldGuideItem.wrappedComponent
4545
icons={attachedMedia}
4646
item={item}
47-
setActiveItem={() => {}}
47+
setActiveItemIndex={() => {}}
4848
/>)
4949

5050
expect(wrapper.find(Markdownz).first().contains(`### ${item.title}`)).to.be.true
@@ -55,7 +55,7 @@ describe('Component > FieldGuideItem', function () {
5555
<FieldGuideItem.wrappedComponent
5656
icons={attachedMedia}
5757
item={item}
58-
setActiveItem={() => { }}
58+
setActiveItemIndex={() => { }}
5959
/>)
6060

6161
expect(wrapper.find(Markdownz).last().contains(item.content)).to.be.true
@@ -66,7 +66,7 @@ describe('Component > FieldGuideItem', function () {
6666
<FieldGuideItem.wrappedComponent
6767
icons={attachedMedia}
6868
item={item}
69-
setActiveItem={() => { }}
69+
setActiveItemIndex={() => { }}
7070
/>)
7171

7272
expect(wrapper.find(Media)).to.have.lengthOf(1)
@@ -78,7 +78,7 @@ describe('Component > FieldGuideItem', function () {
7878
<FieldGuideItem.wrappedComponent
7979
icons={observable.map()}
8080
item={item}
81-
setActiveItem={() => { }}
81+
setActiveItemIndex={() => { }}
8282
/>)
8383

8484
expect(wrapper.find(Media)).to.have.lengthOf(0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import zooTheme from '@zooniverse/grommet-theme'
2+
import React from 'react'
3+
import { Media } from '@zooniverse/react-components'
4+
import PropTypes from 'prop-types'
5+
6+
export default function FieldGuideItemIcon({ alt, className, height, icon, viewBox, width }) {
7+
if (icon && Object.keys(icon).length > 0) {
8+
return (
9+
<Media alt={alt} className={className} fit='contain' height={height} src={icon.src} width={width} />
10+
)
11+
}
12+
13+
return (
14+
<svg className={className} viewBox={viewBox}>
15+
<rect fill={zooTheme.global.colors['accent-2']} height={height} width={width} />
16+
</svg>
17+
)
18+
}
19+
20+
FieldGuideItemIcon.defaultProps = {
21+
alt: '',
22+
className: '',
23+
height: '100%',
24+
icon: {},
25+
viewBox: '0 0 100 100',
26+
width: '100%'
27+
}
28+
29+
FieldGuideItemIcon.propTypes = {
30+
alt: PropTypes.string,
31+
className: PropTypes.string,
32+
height: PropTypes.string,
33+
icon: PropTypes.object,
34+
viewBox: PropTypes.string,
35+
width: PropTypes.string
36+
}

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItemIcon/FieldGuideItemIcon.spec.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './FieldGuideItemIcon'

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItems/FieldGuideItemAnchor.js

+14-34
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
import zooTheme from '@zooniverse/grommet-theme'
21
import { Anchor, Box } from 'grommet'
3-
import styled from 'styled-components'
42
import React from 'react'
53
import { observable } from 'mobx'
6-
import { Markdownz, Media } from '@zooniverse/react-components'
4+
import { Markdownz } from '@zooniverse/react-components'
75
import PropTypes from 'prop-types'
86
import { inject, observer, PropTypes as MobXPropTypes } from 'mobx-react'
7+
import FieldGuideItemIcon from '../FieldGuideItemIcon'
98
import counterpart from 'counterpart'
109
import en from './locales/en'
1110

1211
counterpart.registerTranslations('en', en)
1312

14-
export function Icon({ className, icon }) {
15-
if (icon && Object.keys(icon).length > 0) {
16-
return (
17-
<Media className={className} src={icon.src} />
18-
)
19-
}
20-
21-
return (
22-
<svg className={className} viewBox='0 0 100 100'>
23-
<rect fill={zooTheme.global.colors['accent-2']} height='100' width='100' />
24-
</svg>
25-
)
26-
}
27-
2813
export function AnchorLabel({ className, icons, item }) {
2914
const icon = icons.get(item.icon)
3015
return (
@@ -34,7 +19,7 @@ export function AnchorLabel({ className, icons, item }) {
3419
direction='column'
3520
width='100px'
3621
>
37-
<Icon icon={icon} />
22+
<FieldGuideItemIcon alt={item.title} height='100' icon={icon} width='100' />
3823
<Markdownz>
3924
{item.title}
4025
</Markdownz>
@@ -60,23 +45,18 @@ class FieldGuideItemAnchor extends React.Component {
6045
}
6146

6247
render () {
63-
const { className, icons, row } = this.props
48+
const { className, icons, item } = this.props
49+
const label = <AnchorLabel icons={icons} item={item} />
6450

6551
return (
66-
row.map((item) => {
67-
const label = <AnchorLabel icons={icons} item={item} />
68-
return (
69-
<Anchor
70-
a11yTitle={counterpart('FieldGuideItemAnchor.ariaTitle', { title: item.title })}
71-
className={className}
72-
color='dark-5'
73-
href=''
74-
key={item.title}
75-
label={label}
76-
onClick={(event) => this.onClick(event, item)}
77-
/>
78-
)
79-
})
52+
<Anchor
53+
a11yTitle={counterpart('FieldGuideItemAnchor.ariaTitle', { title: item.title })}
54+
className={className}
55+
color='dark-5'
56+
href=''
57+
label={label}
58+
onClick={(event) => this.onClick(event, item)}
59+
/>
8060
)
8161
}
8262
}
@@ -89,7 +69,7 @@ FieldGuideItemAnchor.wrappedComponent.defaultProps = {
8969
FieldGuideItemAnchor.wrappedComponent.propTypes = {
9070
className: PropTypes.string,
9171
icons: MobXPropTypes.observableMap,
92-
row: PropTypes.arrayOf(PropTypes.object).isRequired,
72+
item: PropTypes.object.isRequired,
9373
setActiveItemIndex: PropTypes.func.isRequired
9474
}
9575

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItems/FieldGuideItems.js

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
import { Box, Grid } from 'grommet'
1+
import { Grid } from 'grommet'
22
import React from 'react'
33
import PropTypes from 'prop-types'
4-
import chunk from 'lodash/chunk'
54
import FieldGuideItemAnchor from './FieldGuideItemAnchor'
65

76
export default function FieldGuideItems({ className, items }) {
8-
const gridRows = chunk(items, 4)
97
return (
10-
<Box basis='full' className={className} direction='row' wrap>
11-
{gridRows.map((row, index) => {
12-
return (
13-
<Grid
14-
columns={['100px', '100px', '100px', '100px']}
15-
key={index}
16-
margin={{ bottom: 'small' }}
17-
gap='medium'
18-
rows={['150px']}
19-
>
20-
<FieldGuideItemAnchor row={row} />
21-
</Grid>
22-
)
23-
})}
24-
</Box>
8+
<Grid
9+
className={className}
10+
columns={{ count: 'fill', size: '100px' }}
11+
margin={{ bottom: 'small' }}
12+
gap='medium'
13+
rows='150px'
14+
width='100%'
15+
>
16+
{items.map((item) => {
17+
return (<FieldGuideItemAnchor key={item.title} item={item} />)})}
18+
</Grid>
2519
)
2620
}
2721

packages/lib-classifier/src/store/FieldGuideStore.js

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const FieldGuideStore = types
9393
}
9494

9595
function setActiveItemIndex (item) {
96+
console.log('calling')
9697
const fieldGuide = self.active
9798
if (fieldGuide) {
9899
const { items } = fieldGuide

0 commit comments

Comments
 (0)