forked from zotero/zoterobib
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate style-selector to custom select input
- Loading branch information
Showing
3 changed files
with
39 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,45 @@ | ||
import React from 'react'; | ||
import React, { useCallback, memo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import cx from 'classnames'; | ||
import { default as Select } from 'react-select'; | ||
|
||
import Select, { SelectDivider, SelectOption } from './ui/select'; | ||
import { citationStylesCount } from '../../../data/citation-styles-data.json'; | ||
|
||
class StyleSelector extends React.Component { | ||
render() { | ||
return ( | ||
<div className={ cx('style-selector', this.props.className ) }> | ||
const StyleSelector = ({ className, citationStyle, citationStyles, onCitationStyleChanged }) => { | ||
const handleMoreStylesTrigger = useCallback( | ||
() => onCitationStyleChanged('install'), [onCitationStyleChanged] | ||
); | ||
|
||
return ( | ||
<div className={ cx('style-selector', className ) }> | ||
<Select | ||
clearable={ false } | ||
searchable={ false} | ||
value={ this.props.citationStyle } | ||
value={ citationStyle } | ||
options={ [ | ||
...this.props.citationStyles.map(cs => ({ | ||
...citationStyles.map(cs => ({ | ||
value: cs.name, | ||
label: cs.title | ||
})), | ||
{ | ||
value: 'install', | ||
label: `${(Math.floor(citationStylesCount / 100) * 100).toLocaleString()}+ other styles available鈥 | ||
} | ||
] } | ||
onChange={ this.props.onCitationStyleChanged } | ||
/> | ||
onChange={ onCitationStyleChanged } | ||
> | ||
<SelectDivider /> | ||
<SelectOption | ||
onTrigger={ handleMoreStylesTrigger } | ||
option={ { label: `${(Math.floor(citationStylesCount / 100) * 100).toLocaleString()}+ other styles available鈥, value: 'install' } } | ||
/> | ||
</Select> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
static propTypes = { | ||
className: PropTypes.string, | ||
citationStyle: PropTypes.string, | ||
citationStyles: PropTypes.array, | ||
onCitationStyleChanged: PropTypes.func | ||
} | ||
StyleSelector.propTypes = { | ||
className: PropTypes.string, | ||
citationStyle: PropTypes.string, | ||
citationStyles: PropTypes.array, | ||
onCitationStyleChanged: PropTypes.func | ||
} | ||
|
||
|
||
export default StyleSelector; | ||
export default memo(StyleSelector); |
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