Skip to content

Commit

Permalink
feat(DateInput): add calendar icon
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Sep 10, 2019
1 parent 7d8cf40 commit abe3266
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 42 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 4 additions & 10 deletions e2e/__tests__/date-input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@ const SUITES = [
baisy.suite('Components/DateInput', 'common', 'open datetime')
.setRootHeight(600)
.setEnhancer(async (iframe) => {
const input = await iframe.waitForXPath('(//input)[5]');
const icon = await iframe.waitForXPath('((//input)[5]/../..//i)[last()]');

await input.click();

await (await iframe.waitForXPath('//input')).click();
await input.click();
await icon.click();
}),
baisy.suite('Components/DateInput', 'common', 'open month picker')
.setRootHeight(600)
.setEnhancer(async (iframe) => {
const input = await iframe.waitForXPath('(//input)[7]');
const icon = await iframe.waitForXPath('((//input)[7]/../..//i)[last()]');

await input.click();

await (await iframe.waitForXPath('//input')).click();
await input.click();
await icon.click();
}),
baisy.suite('Components/DateInputField', 'common'),
];
Expand Down
70 changes: 42 additions & 28 deletions src/components/DateInput/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import 'react-datepicker/dist/react-datepicker.css';

import { DateInputValue } from './DateInputValue';
import { Dropdown } from '../Dropdown';
import * as utils from './DateInput.utils';
import { Icon } from '../Icon';

import { DateInputTag, DateInputCalendarTag } from './DateInput.theme';
import * as utils from './DateInput.utils';

type DateInputProps = {
onChange: (value: ?string) => void,
Expand Down Expand Up @@ -119,6 +121,12 @@ class DateInput extends React.Component<DateInputProps, DateInputState> {
};
}

toggle = () => {
const { isOpen } = this.state;

this.setState({ isOpen: !isOpen });
};

open = () => {
const { isOpen } = this.state;

Expand All @@ -140,33 +148,39 @@ class DateInput extends React.Component<DateInputProps, DateInputState> {
const mask = isMonthPicker ? utils.YEAR_MONTH_MASK : withTime ? utils.DATETIME_MASK : utils.DATE_MASK;

return (
<Dropdown
isOpen={ isOpen && !disabled }
stretch={ stretch }
onCloseDropdown={ this.close }
onOpenDropdown={ this.open }
{ ...rest }
>
<Dropdown.Head onClick={ this.open }>
<DateInputValue
placeholder={ placeholder }
mask={ mask }
value={ textValue }
onChange={ this.onChangeText }
onBlur={ this.onBlur }
clearable={ clearable }
disabled={ disabled }
autoFocus={ autoFocus }
/>
</Dropdown.Head>
<Dropdown.Body withPortal={ withPortal } modifiers={{
preventOverflow: {
boundariesElement: 'viewport',
},
}}>
<DatePicker { ...collectedProps } />
</Dropdown.Body>
</Dropdown>
<DateInputTag stretch={ stretch }>
<DateInputValue
placeholder={ placeholder }
mask={ mask }
value={ textValue }
onChange={ this.onChangeText }
onBlur={ this.onBlur }
clearable={ clearable }
disabled={ disabled }
autoFocus={ autoFocus }
/>
<Dropdown
isOpen={ isOpen && !disabled }
stretch={ stretch }
onCloseDropdown={ this.close }
onOpenDropdown={ this.open }
css={{ flex: 0 }}
{ ...rest }
>
<Dropdown.Head onClick={ this.toggle }>
<DateInputCalendarTag>
<Icon name="Calendar" />
</DateInputCalendarTag>
</Dropdown.Head>
<Dropdown.Body withPortal={ withPortal } placement="bottom-end" modifiers={{
preventOverflow: {
boundariesElement: 'viewport',
},
}}>
<DatePicker { ...collectedProps } />
</Dropdown.Body>
</Dropdown>
</DateInputTag>
);
}
}
Expand Down
37 changes: 35 additions & 2 deletions src/components/DateInput/DateInput.theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import { css } from '@emotion/core';
import { createThemeTag } from '../../theme/createThemeTag';

// eslint-disable-next-line
const [_, theme] = createThemeTag('dateInput', ({ COLORS }: *) => ({
const [DateInputTag, themeDateInput] = createThemeTag('dateInput', ({ COLORS }: *) => ({
root: {
display: 'flex',
flexDirection: 'row',
},
modifiers: {
stretch: {
width: '100%',
},
},
globals: css`
.react-datepicker {
border: 1px solid ${COLORS.PRIMARY_BORDER_COLOR};
Expand Down Expand Up @@ -189,4 +198,28 @@ const [_, theme] = createThemeTag('dateInput', ({ COLORS }: *) => ({
`,
}));

export { theme };
const [DateInputCalendarTag, themeDateInputCalendar] = createThemeTag('dateInputCalendar', ({ COLORS, SIZES }: *) => ({
root: {
display: 'flex',
flexDirection: 'row',
maxHeight: 36,
maxWidth: 36,
minHeight: 36,
minWidth: 36,
alignItems: 'center',
justifyContent: 'center',
borderColor: COLORS.PRIMARY_BORDER_COLOR,
borderTopRightRadius: SIZES.MAIN_BORDER_RADIUS,
borderBottomRightRadius: SIZES.MAIN_BORDER_RADIUS,
borderWidth: 1,
borderStyle: 'solid',
marginLeft: -1,
},
}));

const theme = {
...themeDateInput,
...themeDateInputCalendar,
};

export { theme, DateInputTag, DateInputCalendarTag };
2 changes: 1 addition & 1 deletion src/components/DateInput/DateInputValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type DateInputValueProps = {
};

const DateInputValue = ({ value, onChange, ...props }: DateInputValueProps) => (
<Input onChange={ (val) => onChange({ target: { value: val }}) } value={ value } { ...props } />
<Input css={{ '& > input': { borderTopRightRadius: 0, borderBottomRightRadius: 0 }}} onChange={ (val) => onChange({ target: { value: val }}) } value={ value } { ...props } />
);

export { DateInputValue };
2 changes: 2 additions & 0 deletions src/components/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type DropdownControlledProps = {|
/** Callback to open dropdown */
onOpenDropdown?: () => void,
children: React$Node,
css?: Object,
|}

type DropdownUncontroledProps = {|
Expand All @@ -28,6 +29,7 @@ type DropdownUncontroledProps = {|
/** When true then plate */
stretch?: boolean,
children: React$Node,
css?: Object,
|}

type DropdownContextData = {|
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dropdown/DropdownBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type DropdownBodyProps = {
children: React$Node | ({ closeDropdown: () => void }) => React$Node,

/** Default content position relative target */
placement?: 'top' | 'left' | 'bottom' | 'right' | 'auto',
placement?: 'top' | 'left' | 'bottom' | 'right' | 'auto' | 'bottom-end' | 'bottom-start' | 'top-end' | 'top-start',
/** Default content align relative target*/
pin?: 'left' | 'right',
/** Set body offset relative target */
Expand Down
7 changes: 7 additions & 0 deletions src/components/Icon/glyphs/Calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/components/Icon/glyphs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import Add from './Add.svg';
import Alert from './Alert.svg';
import APIToken from './APIToken.svg';
import Calendar from './Calendar.svg';
import Check from './Check.svg';
import ChevronDown from './ChevronDown.svg';
import ChevronLeft from './ChevronLeft.svg';
Expand Down Expand Up @@ -54,6 +55,7 @@ export {
Add,
Alert,
APIToken,
Calendar,
Check,
ChevronDown,
ChevronLeft,
Expand Down

0 comments on commit abe3266

Please sign in to comment.