feat: add input group prepend component.

This commit is contained in:
Ahmed Bouhuolia
2020-11-19 11:43:53 +02:00
parent e7f88d5786
commit b9e61461ae
7 changed files with 95 additions and 44 deletions

View File

@@ -0,0 +1,9 @@
import React from 'react';
export default function InputPrependText({ text, children }) {
return (
<div class="input-group-prepend">
<span class="input-group-text">{text}</span>
</div>
);
}

View File

@@ -39,6 +39,7 @@ import MoneyInputGroup from './MoneyInputGroup';
import Dragzone from './Dragzone'; import Dragzone from './Dragzone';
import EmptyStatus from './EmptyStatus'; import EmptyStatus from './EmptyStatus';
import DashboardCard from './Dashboard/DashboardCard'; import DashboardCard from './Dashboard/DashboardCard';
import InputPrependText from './Forms/InputPrependText';
const Hint = FieldHint; const Hint = FieldHint;
@@ -84,4 +85,5 @@ export {
Dragzone, Dragzone,
EmptyStatus, EmptyStatus,
DashboardCard, DashboardCard,
InputPrependText,
}; };

View File

@@ -75,9 +75,7 @@ function CustomerFinancialPanel({
<MoneyInputGroup <MoneyInputGroup
value={value} value={value}
prefix={'$'} prefix={'$'}
inputGroupProps={{ inputGroupProps={{ fill: true }}
fill: true,
}}
disabled={customerId} disabled={customerId}
{...field} {...field}
/> />

View File

@@ -37,7 +37,7 @@ const defaultInitialValues = {
inventory_account_id: '', inventory_account_id: '',
category_id: '', category_id: '',
note: '', note: '',
sellable: true, sellable: 1,
purchasable: true, purchasable: true,
}; };

View File

@@ -1,34 +1,33 @@
import React from 'react'; import React from 'react';
import { FastField, Field, ErrorMessage } from 'formik'; import { FastField, Field, ErrorMessage } from 'formik';
import { import { FormGroup, Classes, Checkbox, ControlGroup } from '@blueprintjs/core';
FormGroup,
Classes,
Checkbox,
} from '@blueprintjs/core';
import { import {
AccountsSelectList, AccountsSelectList,
MoneyInputGroup, MoneyInputGroup,
Col, Col,
Row, Row,
Hint, Hint,
InputPrependText,
} from 'components'; } from 'components';
import { FormattedMessage as T } from 'react-intl'; import { FormattedMessage as T } from 'react-intl';
import classNames from 'classnames'; import classNames from 'classnames';
import withAccounts from 'containers/Accounts/withAccounts'; import withAccounts from 'containers/Accounts/withAccounts';
import withSettings from 'containers/Settings/withSettings';
import { compose, inputIntent } from 'utils'; import { compose, inputIntent } from 'utils';
/** /**
* Item form body. * Item form body.
*/ */
function ItemFormBody({ accountsList }) { function ItemFormBody({ accountsList, baseCurrency }) {
return ( return (
<div class="page-form__section page-form__section--selling-cost"> <div class="page-form__section page-form__section--selling-cost">
<Row> <Row>
<Col xs={6}> <Col xs={6}>
{/*------------- Purchasable checbox ------------- */} {/*------------- Purchasable checbox ------------- */}
<FastField name={'sellable'} type="checkbox"> <FastField name={'sellable'} type="checkbox">
{({ field: { onChange, onBlur, name, checked } }) => ( {({ field }) => (
<FormGroup inline={true} className={'form-group--sellable'}> <FormGroup inline={true} className={'form-group--sellable'}>
<Checkbox <Checkbox
inline={true} inline={true}
@@ -38,17 +37,15 @@ function ItemFormBody({ accountsList }) {
</h3> </h3>
} }
name={'sellable'} name={'sellable'}
checked={!!checked} {...field}
onChange={onChange}
onBlur={onBlur}
/> />
</FormGroup> </FormGroup>
)} )}
</FastField> </FastField>
{/*------------- Selling price ------------- */} {/*------------- Selling price ------------- */}
<FastField name={'sell_price'}> <Field name={'sell_price'}>
{({ form, field, field: { value }, meta: { error, touched } }) => ( {({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup <FormGroup
label={<T id={'selling_price'} />} label={<T id={'selling_price'} />}
className={'form-group--sell_price'} className={'form-group--sell_price'}
@@ -56,19 +53,21 @@ function ItemFormBody({ accountsList }) {
helperText={<ErrorMessage name={'sell_price'} />} helperText={<ErrorMessage name={'sell_price'} />}
inline={true} inline={true}
> >
<ControlGroup>
<InputPrependText text={baseCurrency} />
<MoneyInputGroup <MoneyInputGroup
value={value} value={value}
prefix={'$'} prefix={'$'}
inputGroupProps={{ inputGroupProps={{ fill: true }}
medium: true,
...field,
}}
disabled={!form.values.sellable} disabled={!form.values.sellable}
onChange={field.onChange} onChange={(evt, value) => {
form.setFieldValue('sell_price', value);
}}
/> />
</ControlGroup>
</FormGroup> </FormGroup>
)} )}
</FastField> </Field>
{/*------------- Selling account ------------- */} {/*------------- Selling account ------------- */}
<FastField name={'sell_account_id'}> <FastField name={'sell_account_id'}>
@@ -102,8 +101,8 @@ function ItemFormBody({ accountsList }) {
<Col xs={6}> <Col xs={6}>
{/*------------- Sellable checkbox ------------- */} {/*------------- Sellable checkbox ------------- */}
<FastField name={'purchasable'}> <FastField name={'purchasable'} type={'checkbox'}>
{({ form, field: { value, onChange }, meta: { error, touched } }) => ( {({ field }) => (
<FormGroup inline={true} className={'form-group--purchasable'}> <FormGroup inline={true} className={'form-group--purchasable'}>
<Checkbox <Checkbox
inline={true} inline={true}
@@ -112,15 +111,14 @@ function ItemFormBody({ accountsList }) {
<T id={'i_purchase_this_item'} /> <T id={'i_purchase_this_item'} />
</h3> </h3>
} }
checked={value} {...field}
onChange={onChange}
/> />
</FormGroup> </FormGroup>
)} )}
</FastField> </FastField>
{/*------------- Cost price ------------- */} {/*------------- Cost price ------------- */}
<FastField name={'cost_price'}> <Field name={'cost_price'}>
{({ field, form, field: { value }, meta: { error, touched } }) => ( {({ field, form, field: { value }, meta: { error, touched } }) => (
<FormGroup <FormGroup
label={<T id={'cost_price'} />} label={<T id={'cost_price'} />}
@@ -129,18 +127,21 @@ function ItemFormBody({ accountsList }) {
helperText={<ErrorMessage name="cost_price" />} helperText={<ErrorMessage name="cost_price" />}
inline={true} inline={true}
> >
<ControlGroup>
<InputPrependText text={baseCurrency} />
<MoneyInputGroup <MoneyInputGroup
value={value} value={value}
prefix={'$'} prefix={'$'}
inputGroupProps={{ inputGroupProps={{ medium: true }}
medium: true,
...field,
}}
disabled={!form.values.purchasable} disabled={!form.values.purchasable}
onChange={(evt, unformattedValue) => {
form.setFieldValue('cost_price', unformattedValue);
}}
/> />
</ControlGroup>
</FormGroup> </FormGroup>
)} )}
</FastField> </Field>
{/*------------- Cost account ------------- */} {/*------------- Cost account ------------- */}
<FastField name={'cost_account_id'}> <FastField name={'cost_account_id'}>
@@ -180,4 +181,7 @@ export default compose(
withAccounts(({ accountsList }) => ({ withAccounts(({ accountsList }) => ({
accountsList, accountsList,
})), })),
withSettings(({ organization }) => ({
baseCurrency: 'USD',
})),
)(ItemFormBody); )(ItemFormBody);

View File

@@ -8,7 +8,6 @@ import {
import { DateInput } from '@blueprintjs/datetime'; import { DateInput } from '@blueprintjs/datetime';
import { FastField, ErrorMessage } from 'formik'; import { FastField, ErrorMessage } from 'formik';
import { FormattedMessage as T } from 'react-intl'; import { FormattedMessage as T } from 'react-intl';
import moment from 'moment';
import { momentFormatter, compose, tansformDateValue, saveInvoke } from 'utils'; import { momentFormatter, compose, tansformDateValue, saveInvoke } from 'utils';
import classNames from 'classnames'; import classNames from 'classnames';
import { CLASSES } from 'common/classes'; import { CLASSES } from 'common/classes';

View File

@@ -98,6 +98,45 @@ label.bp3-label{
} }
} }
.input-group-prepend{
.input-group-text{
display: flex;
align-items: center;
padding: .375rem .75rem;
margin-bottom: 0;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
text-align: center;
white-space: nowrap;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: .25rem;
height: 100%;
.bp3-form-group &{
padding: .25rem .5rem;
font-size: .875rem;
line-height: 1.5;
border-radius: .2rem;
}
}
}
.bp3-form-group{
.bp3-input-group{
flex: 1 1 auto;
}
.bp3-control-group{
> .input-group-prepend:first-child .input-group-text{
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
}
}
.#{$ns}-html-select{ .#{$ns}-html-select{
.bp3-icon-double-caret-vertical{ .bp3-icon-double-caret-vertical{