Skip to content

Commit 9011f42

Browse files
bernardodiascNick Plekhanovkararade
committed
Add standalone components bundles (#528)
* Add SkillsSelector component (#514) * Add SkillsSelector component * Fix package-lock conflict * Adjust SkillsSelector behaviour * Group external exports together * Update SkillsSelector * Update SkillsSelector * Update SkillsSelector * Reorder import statements * Update SkillsSelector * Build app * Update SkillsSelector * Update SkillsSelector Co-authored-by: Nick Plekhanov <[email protected]> * Move CustomSelect from XP-Reg to XP-UI (#523) * move CustomSelector and rename SkillsSelectorOption to SelectorOption * fix lint * fix flow * add more props * clean props * rebuild * update stories * Add lazyload.js output * Make independent bundles for each client-side-only components * Add error message in the SignupScreen.InputGroup * Add disabled props for Timeframe and SkillsSelector * Replace Select with CustomSelector in SkillsSelector * Update CustomSelector * Build app * Rebuild the app Co-authored-by: Nick Plekhanov <[email protected]> Co-authored-by: Carlos Almeida <[email protected]>
1 parent 66a92ab commit 9011f42

11 files changed

+5060
-5112
lines changed

Diff for: package-lock.json

+4,953-4,964
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/components/ui/CustomSelector.js

+16-38
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ const cx = {
2626
& .Select-control {
2727
display: flex
2828
border: 1px solid ${theme.lineSilver2}
29-
height: auto
29+
height: 60px
3030
padding: 14px 16px
3131
border-radius: 0
3232
cursor: pointer
3333
}
3434
3535
&.is-focused .Select-control {
36-
border: 1px solid ${theme.lineRed} !important
37-
box-shadow: 0 0 3px ${theme.lineRed} !important
36+
border: 1px solid ${theme.lineSilver6} !important
37+
box-shadow: 0 0 3px ${theme.lineSilver6} !important
3838
}
3939
4040
&.is-disabled:hover {
@@ -102,31 +102,13 @@ type Option = {
102102
label: string
103103
}
104104

105-
type Props = {
106-
placeholder?: string,
107-
options?: Array<Option> | null,
108-
disabled?: boolean,
109-
clearable?: boolean,
110-
searchable?: boolean,
111-
value?: any,
112-
onChange?: any
113-
}
105+
type Props = {}
114106

115107
type State = {
116108
selectedOption: Option | null
117109
}
118110

119111
class CustomSelector extends PureComponent<Props, State> {
120-
static defaultProps = {
121-
placeholder: '',
122-
options: null,
123-
disabled: false,
124-
clearable: false,
125-
searchable: false,
126-
value: null,
127-
onChange: null
128-
}
129-
130112
state: State = {
131113
selectedOption: null
132114
}
@@ -136,25 +118,21 @@ class CustomSelector extends PureComponent<Props, State> {
136118
}
137119

138120
render () {
139-
const { placeholder, options, disabled, clearable, searchable, value, onChange } = this.props
140121
const { selectedOption } = this.state
141122

142123
return (
143-
<div>
144-
<Select
145-
{...this.props}
146-
name={'customSelector'}
147-
className={cx.select.toString()}
148-
optionRenderer={SelectorOption}
149-
placeholder={placeholder || 'Select...'}
150-
options={options}
151-
disabled={disabled}
152-
clearable={clearable}
153-
searchable={searchable}
154-
value={value || selectedOption}
155-
onChange={onChange || this.handleSelection}
156-
/>
157-
</div>
124+
<Select
125+
name='CustomSelector'
126+
placeholder='Select...'
127+
optionRenderer={SelectorOption}
128+
onChange={this.handleSelection}
129+
value={selectedOption}
130+
disabled={false}
131+
clearable={false}
132+
searchable={false}
133+
{...this.props}
134+
className={cx.select.toString()}
135+
/>
158136
)
159137
}
160138
}

Diff for: src/components/ui/SignupScreen.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import React from 'react'
66
import Footer from './Footer'
77
import Text from './Text'
88

9-
import { breakpoints } from '../../styles/theme'
9+
import theme, { breakpoints } from '../../styles/theme'
10+
import typo from '../../styles/typo'
1011

1112
const cmz = require('cmz')
1213

@@ -68,11 +69,21 @@ const cx = {
6869

6970
element: cmz(`
7071
margin: 0 0 16px
71-
`)
72+
`),
73+
74+
errorMessage: cmz(
75+
typo.baseText,
76+
`
77+
color: ${theme.typoSubheading}
78+
font-size: 16px
79+
margin: -16px 0 0
80+
`
81+
)
7282
}
7383

7484
type InputGroupProps = {
75-
children?: React$Node
85+
children?: React$Node,
86+
errorMessage?: string
7687
}
7788

7889
type LayoutProps = {
@@ -104,11 +115,14 @@ const Layout = ({ heading, subheading, children }: LayoutProps) => (
104115
</div>
105116
)
106117

107-
const InputGroup = ({ children }: InputGroupProps) => children ? (
118+
const InputGroup = ({ children, errorMessage }: InputGroupProps) => children ? (
108119
<div className={cx.group}>
109120
{React.Children.map(children, (child) => (
110121
<div className={cx.element}>{child}</div>
111122
))}
123+
{errorMessage && (
124+
<div className={cx.errorMessage}>{errorMessage}</div>
125+
)}
112126
</div>
113127
) : null
114128

Diff for: src/components/ui/SignupScreen.stories.js

+18
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ storiesOf('Screens and Layouts|SignupScreen/Debug', module)
6767
</SignupScreen.Layout>
6868
</Body>
6969
))
70+
.add('with error message', () => (
71+
<Body>
72+
<SignupScreen.Layout>
73+
<SignupScreen.InputGroup
74+
errorMessage='This has an error'
75+
>
76+
<SampleLabel />
77+
<InputField placeholder='Input field' />
78+
</SignupScreen.InputGroup>
79+
<SignupScreen.InputGroup
80+
errorMessage='This has an error'
81+
>
82+
<SampleLabel />
83+
<InputField placeholder='Input field' />
84+
</SignupScreen.InputGroup>
85+
</SignupScreen.Layout>
86+
</Body>
87+
))
7088
.add('missing props for Layout', () => (
7189
<SignupScreen.Layout />
7290
))

Diff for: src/components/ui/SkillsSelector.js

+17-94
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,19 @@
22

33
import React, { Component } from 'react'
44
import differenceBy from 'lodash.differenceby'
5-
import Select from 'react-select'
65

76
import SvgIcon from './SvgIcon'
8-
import SelectorOption from './SelectorOption'
9-
10-
import '../../assets/react-select.css'
7+
import CustomSelector from './CustomSelector'
118

129
import theme from '../../styles/theme'
13-
import typo, { typeface } from '../../styles/typo'
10+
import { typeface } from '../../styles/typo'
1411

1512
const cmz = require('cmz')
1613

1714
const cx = {
1815
select: cmz(
19-
typo.baseText,
2016
`
21-
& {
22-
font-size: 18px
23-
text-rendering: optimizeLegibility
24-
-webkit-font-smoothing: antialiased
25-
color: ${theme.typoParagraph}
26-
border: 1px solid transparent
27-
}
28-
29-
& .Select-control {
30-
display: flex
31-
border: 1px solid ${theme.lineSilver2}
32-
height: auto
33-
padding: 21px 16px
34-
}
35-
36-
&:hover,
37-
&.is-focused .Select-control,
38-
&.is-focused:not(.is-open) > .Select-control {
39-
border: 1px solid ${theme.lineRed}
40-
box-shadow: 0 0 4px ${theme.lineRed}
41-
}
42-
43-
& .Select-multi-value-wrapper {
44-
white-space: nowrap
45-
flex: 1
46-
overflow-x: auto
47-
overflow-y: hidden
48-
display: flex
49-
align-items: center
50-
height: 18px
51-
}
52-
53-
& .Select-placeholder::after {
54-
content: '' !important
55-
}
56-
57-
& .Select-placeholder {
58-
padding: 21px 16px
59-
line-height: 1
60-
white-space: nowrap
61-
overflow: hidden
62-
text-overflow: ellipsis
63-
}
64-
65-
& .Select-input {
66-
margin: 0 !important
67-
display: flex !important
68-
align-items: center
69-
padding: 0
70-
}
71-
72-
& .Select-input > input {
73-
border: none
74-
margin: 0
75-
font-weight: 300
76-
}
77-
78-
& .Select-control > *:last-child {
79-
padding: 0
80-
}
81-
82-
& .Select-menu-outer {
83-
top: calc(100% + 5px)
84-
max-height: 270px
85-
background: ${theme.baseBrighter}
86-
border: 1px solid rgba(0, 0, 0, 0.15)
87-
box-shadow: 0 5px 12px rgba(0, 0, 0, 0.15)
88-
border-radius: 0
89-
}
90-
91-
& .Select-menu {
92-
max-height: 270px
93-
}
94-
95-
& .Select-option {
96-
padding: 0
97-
}
17+
9818
`
9919
),
10020

@@ -144,6 +64,7 @@ type Option = {
14464
type Props = {
14565
options?: Array<Option>,
14666
applicantSkills?: Array<Option>,
67+
disabled?: boolean,
14768
onChange?: (selectedSkills: Array<Option>) => void
14869
}
14970

@@ -173,39 +94,41 @@ class SkillsSelector extends Component<Props, State> {
17394
}
17495

17596
renderTag = (skill: Option) => {
97+
const { disabled = false } = this.props
17698
return (
17799
<div key={skill.value} className={cx.tag}>
178100
{skill.label}
179-
<SvgIcon
180-
icon='x'
181-
color='grayscale'
182-
hover='default'
183-
className={cx.removeTag}
184-
onClick={() => this.handleSkillRemove(skill)}
185-
/>
101+
{!disabled && (
102+
<SvgIcon
103+
icon='x'
104+
color='grayscale'
105+
hover='default'
106+
className={cx.removeTag}
107+
onClick={() => this.handleSkillRemove(skill)}
108+
/>
109+
)}
186110
</div>
187111
)
188112
}
189113

190114
render () {
191-
const { options = [] } = this.props
115+
const { options = [], disabled = false } = this.props
192116
const { selectedSkills = [] } = this.state
193117
const placeholder = selectedSkills.length > 0
194118
? 'Add more...'
195119
: 'HTML, React, JavaScript, Postgres, SQL, ...'
196120
const availableOptions = differenceBy(options, selectedSkills, 'value')
197121
return (
198122
<div>
199-
<Select
123+
<CustomSelector
200124
name='skillsSelector'
201125
placeholder={placeholder}
202-
className={cx.select.toString()}
203126
options={availableOptions}
204127
removeSelected
205128
clearable={false}
206129
arrowRenderer={null}
207130
onChange={this.handleSkillSelection}
208-
optionRenderer={SelectorOption}
131+
disabled={disabled}
209132
/>
210133
<div className={cx.tags}>
211134
{selectedSkills.map(this.renderTag)}

Diff for: src/components/ui/SkillsSelector.stories.js

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ storiesOf('Core Components|Form Components/SkillsSelector', module)
4545
))
4646

4747
storiesOf('Core Components|Form Components/SkillsSelector/Debug', module)
48+
.add('disabled state', () => (
49+
<Body>
50+
<SkillsSelector
51+
options={skills}
52+
applicantSkills={applicantSkills}
53+
disabled
54+
/>
55+
</Body>
56+
))
4857
.add('missing props', () => (
4958
<SkillsSelector />
5059
))

0 commit comments

Comments
 (0)