-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #944 from sharetribe/pricing-filter
Pricing filter
- Loading branch information
Showing
42 changed files
with
1,827 additions
and
46 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
73 changes: 73 additions & 0 deletions
73
src/components/FieldRangeSlider/FieldRangeSlider.example.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,73 @@ | ||
/* eslint-disable no-console */ | ||
import React from 'react'; | ||
import { Form as FinalForm, FormSpy } from 'react-final-form'; | ||
import { Button } from '../../components'; | ||
import FieldRangeSlider from './FieldRangeSlider'; | ||
|
||
const formName = 'Styleguide.FieldRangeSlider.Form'; | ||
|
||
const FormComponent = props => ( | ||
<FinalForm | ||
{...props} | ||
formId={formName} | ||
render={fieldRenderProps => { | ||
const { | ||
formId, | ||
handleSubmit, | ||
onChange, | ||
invalid, | ||
pristine, | ||
submitting, | ||
min, | ||
max, | ||
step, | ||
handles, | ||
} = fieldRenderProps; | ||
const submitDisabled = invalid || pristine || submitting; | ||
|
||
return ( | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
handleSubmit(e); | ||
}} | ||
> | ||
<FormSpy onChange={onChange} /> | ||
|
||
<FieldRangeSlider | ||
id={`${formId}.range`} | ||
name="range" | ||
label="Select range" | ||
min={min} | ||
max={max} | ||
step={step} | ||
handles={handles} | ||
/> | ||
|
||
<Button style={{ marginTop: 24 }} type="submit" disabled={submitDisabled}> | ||
Submit | ||
</Button> | ||
</form> | ||
); | ||
}} | ||
/> | ||
); | ||
|
||
export const FieldRangeSliderForm = { | ||
component: FormComponent, | ||
props: { | ||
min: 0, | ||
max: 1000, | ||
step: 5, | ||
handles: [333, 666], | ||
onChange: formState => { | ||
if (formState.dirty) { | ||
console.log('form values changed to:', formState.values); | ||
} | ||
}, | ||
onSubmit: values => { | ||
console.log('submit values:', values); | ||
}, | ||
}, | ||
group: 'custom inputs', | ||
}; |
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,32 @@ | ||
import React from 'react'; | ||
import { Field } from 'react-final-form'; | ||
import classNames from 'classnames'; | ||
import { RangeSlider } from '../../components'; | ||
|
||
const RangeSliderInput = props => { | ||
const { input, handles, ...rest } = props; | ||
const { value, ...inputProps } = input; | ||
|
||
const currentHandles = Array.isArray(value) ? value : handles; | ||
return <RangeSlider {...inputProps} {...rest} handles={currentHandles} />; | ||
}; | ||
|
||
const FieldRangeSlider = props => { | ||
const { rootClassName, className, id, label, ...rest } = props; | ||
|
||
if (label && !id) { | ||
throw new Error('id required when a label is given'); | ||
} | ||
|
||
const inputProps = { id, ...rest }; | ||
const classes = classNames(rootClassName, className); | ||
|
||
return ( | ||
<div className={classes}> | ||
{label ? <label htmlFor={id}>{label}</label> : null} | ||
<Field component={RangeSliderInput} {...inputProps} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FieldRangeSlider; |
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,3 @@ | ||
.example { | ||
overflow-x: hidden; | ||
} |
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,6 +1,7 @@ | ||
import Footer from './Footer'; | ||
import css from './Footer.example.css'; | ||
|
||
export const Default = { | ||
component: Footer, | ||
props: {}, | ||
props: { className: css.example }, | ||
}; |
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,12 @@ | ||
@import '../../marketplace.css'; | ||
|
||
.root { | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
padding: 0; | ||
|
||
@media (--viewportMedium) { | ||
padding: 100px 10vw; | ||
} | ||
} |
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,77 @@ | ||
import React from 'react'; | ||
import { withRouter } from 'react-router-dom'; | ||
import { stringify, parse } from '../../util/urlHelpers'; | ||
|
||
import PriceFilter from './PriceFilter'; | ||
|
||
const URL_PARAM = 'pub_price'; | ||
const RADIX = 10; | ||
|
||
// Helper for submitting example | ||
const handleSubmit = (urlParam, values, history) => { | ||
const { minPrice, maxPrice } = values || {}; | ||
const queryParams = | ||
minPrice != null && maxPrice != null | ||
? `?${stringify({ [urlParam]: [minPrice, maxPrice].join(',') })}` | ||
: ''; | ||
history.push(`${window.location.pathname}${queryParams}`); | ||
}; | ||
|
||
const PriceFilterWrapper = withRouter(props => { | ||
const { history, location } = props; | ||
|
||
const params = parse(location.search); | ||
const price = params[URL_PARAM]; | ||
const valuesFromParams = !!price ? price.split(',').map(v => Number.parseInt(v, RADIX)) : []; | ||
const initialValues = !!price | ||
? { | ||
minPrice: valuesFromParams[0], | ||
maxPrice: valuesFromParams[1], | ||
} | ||
: null; | ||
|
||
return ( | ||
<PriceFilter | ||
{...props} | ||
initialValues={initialValues} | ||
onSubmit={(urlParam, values) => { | ||
console.log('Submit PriceFilterForm with (unformatted) values:', values); | ||
handleSubmit(urlParam, values, history); | ||
}} | ||
/> | ||
); | ||
}); | ||
|
||
export const PriceFilterPopup = { | ||
component: PriceFilterWrapper, | ||
props: { | ||
id: 'PriceFilterPopupExample', | ||
urlParam: URL_PARAM, | ||
min: 0, | ||
max: 1000, | ||
step: 5, | ||
liveEdit: false, | ||
showAsPopup: true, | ||
contentPlacementOffset: -14, | ||
// initialValues: handled inside wrapper | ||
// onSubmit: handled inside wrapper | ||
}, | ||
group: 'misc', | ||
}; | ||
|
||
export const PriceFilterPlain = { | ||
component: PriceFilterWrapper, | ||
props: { | ||
id: 'PriceFilterPlainExample', | ||
urlParam: URL_PARAM, | ||
min: 0, | ||
max: 1000, | ||
step: 5, | ||
liveEdit: true, | ||
showAsPopup: false, | ||
contentPlacementOffset: -14, | ||
// initialValues: handled inside wrapper | ||
// onSubmit: handled inside wrapper | ||
}, | ||
group: 'misc', | ||
}; |
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,19 @@ | ||
import React from 'react'; | ||
import { bool } from 'prop-types'; | ||
import PriceFilterPlain from './PriceFilterPlain'; | ||
import PriceFilterPopup from './PriceFilterPopup'; | ||
|
||
const PriceFilter = props => { | ||
const { showAsPopup, ...rest } = props; | ||
return showAsPopup ? <PriceFilterPopup {...rest} /> : <PriceFilterPlain {...rest} />; | ||
}; | ||
|
||
PriceFilter.defaultProps = { | ||
showAsPopup: false, | ||
}; | ||
|
||
PriceFilter.propTypes = { | ||
showAsPopup: bool, | ||
}; | ||
|
||
export default PriceFilter; |
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,57 @@ | ||
@import '../../marketplace.css'; | ||
|
||
.root { | ||
position: relative; | ||
padding-top: 24px; | ||
padding-bottom: 17px; | ||
border-bottom: 1px solid var(--matterColorNegative); | ||
} | ||
|
||
.filterLabel, | ||
.filterLabelSelected { | ||
@apply --marketplaceH3FontStyles; | ||
|
||
/* Baseline adjustment for label text */ | ||
margin-top: 0; | ||
margin-bottom: 12px; | ||
padding: 4px 0 2px 0; | ||
} | ||
|
||
.filterLabel { | ||
color: var(--matterColorDark); | ||
} | ||
|
||
.filterLabelSelected { | ||
color: var(--marketplaceColor); | ||
} | ||
|
||
.labelButton { | ||
/* Override button styles */ | ||
outline: none; | ||
text-align: left; | ||
border: none; | ||
padding: 0; | ||
cursor: pointer; | ||
} | ||
|
||
.clearButton { | ||
@apply --marketplaceH5FontStyles; | ||
font-weight: var(--fontWeightMedium); | ||
color: var(--matterColorAnti); | ||
|
||
/* Layout */ | ||
display: inline; | ||
float: right; | ||
margin-top: 6px; | ||
padding: 0; | ||
|
||
/* Override button styles */ | ||
outline: none; | ||
text-align: left; | ||
border: none; | ||
|
||
&:focus, | ||
&:hover { | ||
color: var(--matterColor); | ||
} | ||
} |
Oops, something went wrong.