mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
33
src/components/Utils/Choose.js
Normal file
33
src/components/Utils/Choose.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import If from './If';
|
||||
|
||||
const Choose = (props) => {
|
||||
let when = null;
|
||||
let otherwise = null;
|
||||
|
||||
React.Children.forEach(props.children, (children) => {
|
||||
if (children.props.condition === undefined) {
|
||||
otherwise = children;
|
||||
} else if (!when && children.props.condition === true) {
|
||||
when = children;
|
||||
}
|
||||
});
|
||||
|
||||
return when || otherwise;
|
||||
};
|
||||
|
||||
Choose.propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
Choose.When = If;
|
||||
|
||||
Choose.Otherwise = ({ render, children }) => (render ? render() : children);
|
||||
|
||||
Choose.Otherwise.propTypes = {
|
||||
children: PropTypes.node,
|
||||
render: PropTypes.func,
|
||||
};
|
||||
|
||||
export default Choose;
|
||||
11
src/components/Utils/For.js
Normal file
11
src/components/Utils/For.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const For = ({render, of}) => of.map((item, index) => render(item, index));
|
||||
|
||||
For.propTypes = {
|
||||
of: PropTypes.array.isRequired,
|
||||
render: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default For;
|
||||
19
src/components/Utils/FormatDate.js
Normal file
19
src/components/Utils/FormatDate.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
/**
|
||||
* Format the given date.
|
||||
*/
|
||||
export function FormatDate({ value, format = 'YYYY MMM DD' }) {
|
||||
const localizedFormat = intl.get(`date_formats.${format}`);
|
||||
|
||||
return moment().format(localizedFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format date table cell.
|
||||
*/
|
||||
export function FormatDateCell({ value, column: { formatDate } }) {
|
||||
return <FormatDate value={value} {...formatDate} />;
|
||||
}
|
||||
10
src/components/Utils/FormatNumber.js
Normal file
10
src/components/Utils/FormatNumber.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import { formattedAmount } from 'utils';
|
||||
|
||||
export function FormatNumber({ value, currency = '', noZero }) {
|
||||
return formattedAmount(value, currency, { noZero });
|
||||
}
|
||||
|
||||
export function FormatNumberCell({ value, column: { formatNumber } }) {
|
||||
return <FormatNumber value={value} {...formatNumber} />;
|
||||
}
|
||||
13
src/components/Utils/If.js
Normal file
13
src/components/Utils/If.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const If = props => props.condition
|
||||
? (props.render ? props.render() : props.children) : null;
|
||||
|
||||
If.propTypes = {
|
||||
// condition: PropTypes.bool.isRequired,
|
||||
children: PropTypes.node,
|
||||
render: PropTypes.func
|
||||
};
|
||||
|
||||
export default If;
|
||||
4
src/components/Utils/index.js
Normal file
4
src/components/Utils/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
export * from './FormatNumber';
|
||||
export * from './FormatDate';
|
||||
Reference in New Issue
Block a user