mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat(currencies): add currency select.
This commit is contained in:
76
src/components/Currencies/CurrencySelect.js
Normal file
76
src/components/Currencies/CurrencySelect.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
|
||||||
|
import { MenuItem, Button } from '@blueprintjs/core';
|
||||||
|
import { FSelect } from '../Forms';
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {*} query
|
||||||
|
* @param {*} currency
|
||||||
|
* @param {*} _index
|
||||||
|
* @param {*} exactMatch
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const currencyItemPredicate = (query, currency, _index, exactMatch) => {
|
||||||
|
const normalizedTitle = currency.currency_code.toLowerCase();
|
||||||
|
const normalizedQuery = query.toLowerCase();
|
||||||
|
|
||||||
|
if (exactMatch) {
|
||||||
|
return normalizedTitle === normalizedQuery;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
`${currency.currency_code}. ${normalizedTitle}`.indexOf(
|
||||||
|
normalizedQuery,
|
||||||
|
) >= 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {*} currency
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const currencyItemRenderer = (currency, { handleClick, modifiers, query }) => {
|
||||||
|
return (
|
||||||
|
<MenuItem
|
||||||
|
active={modifiers.active}
|
||||||
|
disabled={modifiers.disabled}
|
||||||
|
text={currency.currency_name}
|
||||||
|
label={currency.currency_code.toString()}
|
||||||
|
key={currency.id}
|
||||||
|
onClick={handleClick}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const currencySelectProps = {
|
||||||
|
itemPredicate: currencyItemPredicate,
|
||||||
|
itemRenderer: currencyItemRenderer,
|
||||||
|
valueAccessor: 'currency_code',
|
||||||
|
labelAccessor: 'currency_code',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {*} currencies
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function CurrencySelect({ currencies, ...rest }) {
|
||||||
|
return (
|
||||||
|
<FSelect
|
||||||
|
{...currencySelectProps}
|
||||||
|
{...rest}
|
||||||
|
items={currencies}
|
||||||
|
input={CurrnecySelectButton}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {*} label
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function CurrnecySelectButton({ label }) {
|
||||||
|
return <Button text={label ? label : intl.get('select_currency_code')} />;
|
||||||
|
}
|
||||||
1
src/components/Currencies/index.js
Normal file
1
src/components/Currencies/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './CurrencySelect'
|
||||||
@@ -101,6 +101,7 @@ export * from './FeatureGuard';
|
|||||||
export * from './ExchangeRate';
|
export * from './ExchangeRate';
|
||||||
export * from './Branches';
|
export * from './Branches';
|
||||||
export * from './Warehouses';
|
export * from './Warehouses';
|
||||||
|
export * from './Currencies';
|
||||||
|
|
||||||
const Hint = FieldHint;
|
const Hint = FieldHint;
|
||||||
|
|
||||||
@@ -169,5 +170,4 @@ export {
|
|||||||
BaseCurrency,
|
BaseCurrency,
|
||||||
MoreMenuItems,
|
MoreMenuItems,
|
||||||
CustomSelectList,
|
CustomSelectList,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user