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 7 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,589 changes: 21,589 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
"module": "lib.esm.js",
"types": "index.d.ts",
"dependencies": {
"@date-io/moment": "^1.3.13",
"@material-ui/core": "^4.10.2",
"@material-ui/icons": "^4.9.1",
"@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": {}

"moment": "^2.29.1",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-router-dom": "^5.2.0"
Expand Down
40 changes: 40 additions & 0 deletions src/core/TimePicker/TimePicker.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 { TimePicker } from './TimePicker';

storiesOf('TimePicker', module)
// Litmus Portal
.add('Litmus Portal', () => (
<ThemedBackground platform="litmus-portal">
<TimePicker onChange={() => console.log('Time Changed')} />
</ThemedBackground>
))

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

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

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

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

interface TimePickerProps extends BaseTimePickerProps {
value?: string;
}

const TimePicker: React.FC<TimePickerProps> = ({ value }) => {
const date = value ? value : '2020 12:30 PM';
const [selectedDate, handleDateChange] = useState<number>(Date.parse(date));
return (
<MuiPickersUtilsProvider utils={MomentUtils}>
<KeyboardTimePicker
margin="normal"
id="time-picker"
autoOk
okLabel="Save"
label="Time picker"
value={selectedDate}
data-testid="timepicker"
onChange={(newDate: any) => handleDateChange(newDate)}
KeyboardButtonProps={{
'aria-label': 'change time',
}}
/>
</MuiPickersUtilsProvider>
);
};
export { TimePicker };
16 changes: 16 additions & 0 deletions src/core/TimePicker/__tests__/TimerPicker.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 { TimePicker } from '../TimePicker';

describe('Timepicker component', () => {
it('Renders', () => {
const { getByTestId } = render(
<KuberaThemeProvider platform="kubera-chaos">
<TimePicker onChange={() => console.log('Time Changed')} />
</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 { KeyboardTimePickerProps } from '@material-ui/pickers';

export type BaseTimePickerProps = Omit<KeyboardTimePickerProps, 'value'>;
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 './TimePicker';
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './Button';
export * from './TimePicker';
export * from './ProgressBar';
export * from './Text';
export * from './Pills';
Expand Down