Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timepicker component #31

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21,605 changes: 21,605 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@
"module": "lib.esm.js",
"types": "index.d.ts",
"dependencies": {
"@date-io/date-fns": "^1.3.13",
"@date-io/moment": "^1.3.13",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are packages for Date Picker, we are building a time picker so this is not required here.

"@material-ui/core": "^4.10.2",
"@material-ui/pickers": "^3.2.10",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also need this as a peer dependency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hasmik8 we can add the same in "peerDependencies": {}

"date-fns": "^2.16.1",
"moment": "^2.29.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again these packages are for date pickers, not time pickers. You'd only need KeyboardTimePicker from @material-ui/pickers

"react": "^16.9.0",
"react-dom": "^16.9.0"
},
Expand Down
40 changes: 40 additions & 0 deletions src/core/Timepicker/BaseTimePicker.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { storiesOf } from '@storybook/react';
import React from 'react';
import { ThemedBackground } from '../../utils/storybook';
import { BaseTimePicker } from './BaseTimePicker';

storiesOf('TimePicker', module)
// Litmus Portal
.add('Litmus Portal', () => (
<ThemedBackground platform="litmus-portal">
<BaseTimePicker onChange={() => console.log('timepicker')} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<BaseTimePicker onChange={() => console.log('timepicker')} />
<BaseTimePicker onChange={() => console.log('Time Changed')} />

</ThemedBackground>
))

// Kubera Chaos
.add('Kubera Chaos', () => (
<ThemedBackground platform="kubera-chaos">
<BaseTimePicker onChange={() => console.log('timepicker')} />
</ThemedBackground>
))

// Kubera Propel
.add('Kubera Propel', () => (
<ThemedBackground platform="kubera-propel">
<BaseTimePicker onChange={() => console.log('timepicker')} />
</ThemedBackground>
))

// Kubera Portal
.add('Kubera Portal', () => (
<ThemedBackground platform="kubera-portal">
<BaseTimePicker onChange={() => console.log('timepicker')} />
</ThemedBackground>
))

// Kubera Core
.add('Kubera Core', () => (
<ThemedBackground platform="kubera-core">
<BaseTimePicker onChange={() => console.log('timepicker')} />
</ThemedBackground>
));
26 changes: 26 additions & 0 deletions src/core/Timepicker/BaseTimePicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'date-fns';
import React, { useState } from 'react';
import MomentUtils from '@date-io/moment';
import { MuiPickersUtilsProvider, TimePicker } from '@material-ui/pickers';
import { BaseTimePickerProps } from './base';

interface TimePickerProps extends BaseTimePickerProps {
value?: Date;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time Picker will not take a Date


const BaseTimePicker: React.FC<TimePickerProps> = ({ value }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const BaseTimePicker: React.FC<TimePickerProps> = ({ value }) => {
const TimePicker: React.FC = () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@S-ayanide no need to pass this value via props?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date is not required to be passed as props

const date = value != undefined ? value : new Date();
const [selectedDate, handleDateChange] = useState<Date | null>(date);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date isn't required in time picker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@S-ayanide that is , the value shouldn't be passes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, Date shouldn't be passed

return (
<MuiPickersUtilsProvider utils={MomentUtils}>
<TimePicker
autoOk
okLabel="Save"
value={selectedDate}
data-testid="timepicker"
onChange={(newDate: any) => handleDateChange(newDate)}
/>
</MuiPickersUtilsProvider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a simple KeyboardTimePicker instead! And avoid the MUI utility wrapper if possible!

<KeyboardTimePicker
          margin="normal"
          id="time-picker"
          label="Time picker"
          value={selectedTime}
          onChange={handleTimeChange}
          KeyboardButtonProps={{
            'aria-label': 'change time',
          }}
        />

);
};
export { BaseTimePicker };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export { BaseTimePicker };
export { TimePicker };

16 changes: 16 additions & 0 deletions src/core/Timepicker/__tests__/BaseTimerPicker.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { render } from '@testing-library/react';
import React from 'react';
import { KuberaThemeProvider } from '../../../theme';
import { BaseTimePicker } from '../BaseTimePicker';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { BaseTimePicker } from '../BaseTimePicker';
import { TimePicker } from '../TimePicker';


describe('Timepicker component', () => {
it('Renders', () => {
const { getByTestId } = render(
<KuberaThemeProvider platform="kubera-chaos">
<BaseTimePicker onChange={() => console.log('timepicker')} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<BaseTimePicker onChange={() => console.log('timepicker')} />
<TimePicker onChange={() => console.log('timepicker')} />

</KuberaThemeProvider>
);

expect(getByTestId('timepicker')).toBeTruthy();
});
});
3 changes: 3 additions & 0 deletions src/core/Timepicker/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TimePickerProps } from '@material-ui/pickers';

export type BaseTimePickerProps = Omit<TimePickerProps, 'value'>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to use the basic props provided by KeyboardTimePicker, there's no requirement to omit any

1 change: 1 addition & 0 deletions src/core/Timepicker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './BaseTimePicker';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export * from './BaseTimePicker';
export * from './TimePicker';

5 changes: 5 additions & 0 deletions src/core/Timepicker/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { makeStyles } from '@material-ui/core';

const useStyles = makeStyles(() => ({}));

export { useStyles };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no styles required we can simply not have a styles.ts file instead!

1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Button';
export * from './Timepicker';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export * from './Timepicker';
export * from './TimePicker';

Can we also camel case time file name for the same!