Skip to content

Commit

Permalink
feat: add bottom sheet and picker's base component
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-master committed Mar 24, 2021
1 parent 817d786 commit 37793f9
Show file tree
Hide file tree
Showing 8 changed files with 768 additions and 34,296 deletions.
34,573 changes: 568 additions & 34,005 deletions package-lock.json

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"name": "@persian-tools/persian-mobile-datepicker",
"version": "0.0.1",
"description": "Persian Mobile Date and Time picker",
"main": "build/persian-mobile-datepicker.js",
"exports": "build/persian-mobile-datepicker.modern.js",
"esmodule": "build/persian-mobile-datepicker.modern.js",
"module": "build/persian-mobile-datepicker.module.js",
"umd:main": "build/persian-mobile-datepicker.umd.js",
"unpkg": "build/persian-mobile-datepicker.umd.js",
"types": "build/persian-mobile-datepicker.d.ts",
"source": "src/index.tsx",
"main": "build/index.js",
"esmodule": "build/index.modern.js",
"module": "build/index.module.js",
"umd:main": "build/index.umd.js",
"unpkg": "build/index.umd.js",
"types": "build/index.d.ts",
"scripts": {
"build": "microbundle-crl src/index.tsx",
"postbuild": "mv ./build/index.d.ts ./build/persian-mobile-datepicker.d.ts",
"dev": "microbundle-crl bundler watch",
"dev": "microbundle-crl watch --no-css-modules",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
Expand Down Expand Up @@ -42,8 +41,11 @@
"homepage": "https://github.com/persian-tools/persian-mobile-datepicker#readme",
"dependencies": {
"@persian-tools/persian-tools": "^1.6.0-beta.4",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"framer-motion": "^4.0.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-modal-sheet": "^1.3.0",
"rmc-picker": "^5.0.10",
"styled-components": "^5.2.1"
},
"devDependencies": {
Expand All @@ -55,19 +57,18 @@
"@storybook/react": "^6.1.21",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.8.3",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.33",
"@testing-library/user-event": "^13.0.10",
"@types/jest": "^26.0.21",
"@types/node": "^14.14.35",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.2",
"@types/styled-components": "^5.1.7",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"@types/react-dom": "^17.0.3",
"@types/styled-components": "^5.1.9",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.2.2",
"chromatic": "^5.6.3",
"cross-env": "^7.0.3",
"eslint": "^7.21.0",
"eslint": "^7.22.0",
"eslint-config-react-app": "^6.0.0",
"gh-pages": "^3.1.0",
"microbundle-crl": "^0.13.11",
Expand All @@ -76,7 +77,7 @@
"typescript": "^4.2.3"
},
"peerDependencies": {
"react": "^17.0.1"
"react": "^16.5.0"
},
"browserslist": {
"production": [
Expand Down
194 changes: 97 additions & 97 deletions src/components/WheelPicker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,112 +1,112 @@
import React from 'react';
// Global Components
import MultiPicker from 'rmc-picker/es/MultiPicker';
import Picker from 'rmc-picker/es/Picker';
// Styles
import { GlobalStyle } from './styles';
// Helpers
import {
columnName,
mapSelectedValueToDate,
prefixClassName,
} from '../../helpers';
// Types
import type { WheelPickerProps } from './index.types';
import type { PickerMultipleColumns, WheelPickerProps } from './index.types';

export const WheelPicker: React.FC<WheelPickerProps> = () => {
export const WheelPicker: React.FC<WheelPickerProps> = (props) => {
const [value, setValue] = React.useState<number[]>();
const prefix = prefixClassName(props.prefix!);
const pickerColumns: PickerMultipleColumns = [
[1399, 1400, 1401, 1402, 1403],
[
'فروردین',
'اردیبهشت',
'خرداد',
'تیر',
'مرداد',
'شهریور',
'مهر',
'آبان',
'آذر',
'دی',
'بهمن',
'اسفند',
],
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
],
];

function onChange(value: Array<number>) {
console.log(
'onChange selected value',
value,
'value',
mapSelectedValueToDate(pickerColumns, value),
);
setValue(value);
}
return (
<React.Fragment>
<div className="wheelpicker shown" style={{ display: 'block' }}>
<div className="wheelpicker-backdrop"></div>
<div className="wheelpicker-panel">
<div className="wheelpicker-actions">
<button type="button" className="btn-cancel">
بستن
</button>
<button type="button" className="btn-set">
تایید
</button>
<h4 className="wheelpicker-title"></h4>
</div>
<div className="wheelpicker-main">
<div className="wheelpicker-wheels">
<div className="wheelpicker-wheel" style={{ height: 170 }}>
<ul
className="wheelpicker-wheel-scroller"
style={{
transform: 'translate3d(0px, 0px, 0px)',
marginTop: 68,
}}
>
<li className="wheelpicker-item ">1400</li>
<li className="wheelpicker-item wheelpicker-item-selected">
1399
</li>
<li className="wheelpicker-item">1398</li>
<li className="wheelpicker-item">1397</li>
<li className="wheelpicker-item">1396</li>
<li className="wheelpicker-item">1395</li>
<li className="wheelpicker-item">1394</li>
<li className="wheelpicker-item">1393</li>
<li className="wheelpicker-item">1392</li>
<li className="wheelpicker-item">1391</li>
<li className="wheelpicker-item">1390</li>
</ul>
</div>
<div className="wheelpicker-wheel" style={{ height: 170 }}>
<ul
className="wheelpicker-wheel-scroller"
style={{
transform: 'translate3d(0px, 0px, 0px)',
marginTop: 68,
}}
>
<li className="wheelpicker-item wheelpicker-item-selected">
اسفند
</li>
</ul>
</div>
<div className="wheelpicker-wheel" style={{ height: 170 }}>
<ul
className="wheelpicker-wheel-scroller"
style={{
transform: 'translate3d(0px, 0px, 0px)',
marginTop: 68,
}}
>
<li className="wheelpicker-item wheelpicker-item-selected">
19
</li>
<li className="wheelpicker-item">20</li>
<li className="wheelpicker-item">21</li>
<li className="wheelpicker-item">22</li>
<li className="wheelpicker-item">23</li>
<li className="wheelpicker-item">24</li>
<li className="wheelpicker-item">25</li>
<li className="wheelpicker-item">26</li>
<li className="wheelpicker-item">27</li>
<li className="wheelpicker-item">28</li>
<li className="wheelpicker-item">29</li>
<li className="wheelpicker-item">30</li>
</ul>
</div>
</div>
<div
className="wheelpicker-mask wheelpicker-mask-top"
style={{ height: 67 }}
></div>
<div className="wheelpicker-mask wheelpicker-mask-current"></div>
<div
className="wheelpicker-mask wheelpicker-mask-btm"
style={{ height: 67 }}
></div>
</div>
</div>
</div>
<MultiPicker selectedValue={value} onValueChange={onChange}>
{pickerColumns.map((column, index) => {
return (
<Picker
key={index}
indicatorClassName={prefix(
`indicator ${prefix(`${columnName(index)}-column`)}`,
)}
>
{column.map((columnValues, columnValuesIndex) => {
return (
<Picker.Item
key={columnValuesIndex}
className={prefix('view-item')}
value={columnValuesIndex}
>
{columnValues}
</Picker.Item>
);
})}
</Picker>
);
})}
</MultiPicker>
<GlobalStyle />
</React.Fragment>
);
};

WheelPicker.defaultProps = {
data: [],
visibleRows: 5,
rowHeight: 34,
parseValue(value) {
return value.split(' ');
},
formatValue(value) {
return value.join(' ');
},
};
19 changes: 6 additions & 13 deletions src/components/WheelPicker/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ export interface WheelPickerSelectEvent extends WheelPickerDataModel {
}

export interface WheelPickerProps {
// CSS classnames prefix
prefix?: string;
// Array of data in each column
data: Array<WheelPickerDataModel>;
// Default column value
defaultValue?: WheelPickerDataModel;
// Number of visible rows(Prefer to write an odd number)
visibleRows?: number;
// Rows height
rowHeight?: number;
// The value filled into the el element when saving
parseValue?: (value: string) => Array<string>;
// Get the default value from the el element
formatValue?: (value: Array<string>) => string;
// Click the mask layer to close the component (equivalent to cancel)
hideOnBackdrop: boolean;
hideOnBackdrop?: boolean;
// Title
title?: string;
// Triggered when the component DOM is generated, the parameter is the component element
Expand All @@ -30,10 +24,9 @@ export interface WheelPickerProps {
onChange?: (selected: WheelPickerSelectEvent) => void;
// Triggered when you click OK, the parameter is an array of entries
onSelect?: (selected: WheelPickerSelectEvent) => void;
// Show the Picker
open: boolean;
// Triggered when cancel is clicked
onClose?: () => void;
// Disabled
disabled?: boolean;
}

export type PickerSingleColumn = Array<string | number>;
export type PickerMultipleColumns = Array<PickerSingleColumn>;
Loading

0 comments on commit 37793f9

Please sign in to comment.