Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 449a572

Browse files
committed
update samples and fix minor bugs
1 parent cc7a2d5 commit 449a572

File tree

7 files changed

+99
-53
lines changed

7 files changed

+99
-53
lines changed

README.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ this component is a simple react component that use [jb-date-input](https://gith
3232
Demo & Sample
3333
in github: <https://javadbat.github.io/jb-date-input-react/>
3434
in codepen: <https://codepen.io/javadbat/pen/qBRyYKY>
35+
in codeSandBox: [codeSandbox preview](https://3f63dj.csb.app/samples/jb-date-input) for just see the demo and [codeSandbox editor](https://codesandbox.io/p/sandbox/jb-design-system-3f63dj?file=%2Fsrc%2Fsamples%2FJBDateInput.tsx) if you want to see and play with code
3536

3637
## instructions
3738

@@ -59,8 +60,8 @@ import {JBDateInput} from 'jb-date-input-react';
5960

6061
## format
6162

62-
defualt format of date input is 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' that compatible and exact format of `new Date().toISOString()`
63-
you can change it however you need and `[Z]` mean the exact Z charecter that used in ISO standard format `YYYY-MM-DDTHH:mm:ss.SSSZ[Z]` => `2012-06-21T00:00:00.000+3:30Z`
63+
default format of date input is 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' that compatible and exact format of `new Date().toISOString()`
64+
you can change it however you need and `[Z]` mean the exact Z character that used in ISO standard format `YYYY-MM-DDTHH:mm:ss.SSSZ[Z]` => `2012-06-21T00:00:00.000+3:30Z`
6465
you can change format by format attribute:
6566

6667
```jsx
@@ -186,9 +187,9 @@ when date input value is empty we show today year and month in opened calendar b
186187
<JBDateInput inputType="JALALI" calendarDefaultDateView={{year:1350, month:3}}></JBDateInput>
187188
```
188189
## show persian number
189-
if you want to show persian number instead of English number char you just have to set `usePersianNumber` prop like this:
190+
if you want to show persian number instead of English number char you just have to set `showPersianNumber` prop like this:
190191
```jsx
191-
<JBDateInput usePersianNumber={true}></JBDateInput>
192+
<JBDateInput showPersianNumber={true}></JBDateInput>
192193
```
193194
## customize calendar button trigger
194195

@@ -297,4 +298,12 @@ in jb-input you can put icon or any other custom html DOM in input box. to doing
297298
<div slot="end-section">after</div>
298299
<div slot="start-section">before</div>
299300
</JBDateInput>
300-
```
301+
```
302+
303+
## Other Related Docs:
304+
305+
- see [jb-date-input](https://github.com/javadbat/jb-date-input) if you want to use this component as a web-component
306+
307+
- see [All JB Design system Component List](https://github.com/javadbat/design-system/blob/master/docs/component-list.md) for more components
308+
309+
- use [Contribution Guide](https://github.com/javadbat/design-system/blob/master/docs/contribution-guide.md) if you want to contribute in this component.

docs/package-lock.json

+40-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"eslint-config-next": "13.2.3",
1717
"jb-calendar": "^4.0.3",
1818
"jb-date-input": "^3.13.0",
19-
"jb-date-input-react": "^2.6.1",
19+
"jb-date-input-react": "^5.0.0",
2020
"next": "13.2.3",
2121
"react": "18.2.0",
2222
"react-dom": "18.2.0",

docs/src/components/samples/Samples.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import React, { useEffect } from 'react';
22
import { FormalTheme, RTLJBDateInput, SamplesSectionWrapper, SamplesTitle, SamplesWrapper } from './styled';
33
import dynamic from 'next/dynamic';
4-
import { JBDateInputValueObject } from 'jb-date-input-react';
4+
import { JBDateInputValueObject, ValidationItem, ValidationValue } from 'jb-date-input-react';
55
enum InputTypes {
66
jalali = 'JALALI',
77
gregorian = 'GREGORIAN'
88
}
99
const JBDateInput = dynamic(() => import('jb-date-input-react').then(module => module.JBDateInput), {
1010
ssr: false,
1111
});
12-
const validationList = [
12+
const validationList:ValidationItem<ValidationValue>[] = [
1313
{
1414
validator: /^13.*$/g,
1515
message: 'تاریخ باید تنها در قرن 13 شمسی باشد'
1616
},
1717
{
18-
validator: (inputedText: string, valueObject: JBDateInputValueObject, valueText: string) => {
19-
//you can use raw inputed text or formatted text in expected value in argumants
18+
validator: ({text,inputObject,valueObject,valueText}) => {
19+
//you can use raw inputted text or formatted text in expected value in arguments
2020
//you have access to both jalali and gregorian date object here in valueObject
2121
// remember valueObject and valueText are both empty and null when date is incomplete
22-
//if you want to validate incomplete date you can use inputedText
22+
//if you want to validate incomplete date you can use inputtedText
2323
return valueObject.jalali.day == 15;
2424
},
2525
message: 'باید تاریخ حتما 15 ماه انتخاب شود'
@@ -33,8 +33,8 @@ function Samples() {
3333
</SamplesTitle>
3434
<SamplesWrapper>
3535
<JBDateInput label="simple date:">{ }</JBDateInput>
36-
<JBDateInput label="with persian number" usePersianNumber={true}>{ }</JBDateInput>
37-
<RTLJBDateInput label="راست به چپ" usePersianNumber={true}>{ }</RTLJBDateInput>
36+
<JBDateInput label="with persian number" showPersianNumber={true}>{ }</JBDateInput>
37+
<RTLJBDateInput label="راست به چپ" showPersianNumber={true}>{ }</RTLJBDateInput>
3838
<JBDateInput label="with default value:" value="2020-08-10T08:51:23.176Z">{ }</JBDateInput>
3939
<JBDateInput label="with min and max value:" value="2020-08-10T08:51:23.176Z" min="2020-08-05T08:51:23.176Z" max="2020-08-15T08:51:23.176Z">{ }</JBDateInput>
4040
<JBDateInput label="with validation" validationList={validationList}>{ }</JBDateInput>
@@ -62,10 +62,10 @@ function Samples() {
6262
</div>
6363
</JBDateInput>
6464
<JBDateInput label="with inner-box section">
65-
<div slot="end-section">a</div>
66-
<div slot="start-section">b</div>
65+
<div slot="end-section">a</div>
66+
<div slot="start-section">b</div>
6767
</JBDateInput>
68-
<JBDateInput label='with custom month name' jalaliMonthList={["حَمَل","ثَور","جَوزا","سَرَطان","اَسَد","سُنبُله","میزان","عَقرَب","قَوس","جَدْی","دَلو","حوت"]}></JBDateInput>
68+
<JBDateInput label='with custom month name' jalaliMonthList={["حَمَل", "ثَور", "جَوزا", "سَرَطان", "اَسَد", "سُنبُله", "میزان", "عَقرَب", "قَوس", "جَدْی", "دَلو", "حوت"]}></JBDateInput>
6969
<FormalTheme label="more formal look">{ }</FormalTheme>
7070
</SamplesWrapper>
7171

docs/src/components/samples/styled.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ export const SamplesWrapper = styled.div`
2424
}
2525
`;
2626
export const FormalTheme = styled(JBDateInput)`
27-
--jb-date-input-border-radius:0;
28-
--jb-date-input-border-color:#888;
29-
--jb-date-input-border-color-focus:#000;
30-
--jb-date-input-bgcolor:#fff;
31-
--jb-date-input-message-box-color:blue;
32-
--jb-date-input-border-bottom-width:1px;
33-
--jb-date-input-label-font-size :1.3em;
34-
--jb-date-input-value-color:#434343;
35-
--jb-date-input-value-font-size:1.3em;
36-
--jb-date-input-calender-wrapper-bg-color:#fefefe;
37-
--jb-date-input-calender-wrapper-border-radius:0;
27+
--jb-input-border-radius:0;
28+
--jb-input-border-color:#888;
29+
--jb-input-border-color-focus:#000;
30+
--jb-input-bgcolor:#fff;
31+
--jb-input-message-box-color:blue;
32+
--jb-input-border-bottom-width:1px;
33+
--jb-input-label-font-size :1.3em;
34+
--jb-input-value-color:#434343;
35+
--jb-input-value-font-size:1.3em;
36+
--jb-input-calender-wrapper-bg-color:#fefefe;
37+
--jb-input-calender-wrapper-border-radius:0;
3838
--jb-calendar-arrow-button-border-radius:0;
3939
`;
4040
export const RTLJBDateInput = styled(JBDateInput)`

lib/JBDateInput.tsx

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import React, { useEffect, useRef, useState, useImperativeHandle, useCallback } from 'react';
1+
import React, { useEffect, useRef, useState, useImperativeHandle, useCallback, MutableRefObject, RefObject, ReactNode, forwardRef, DetailedHTMLProps, HTMLAttributes } from 'react';
22
import 'jb-date-input';
33
// eslint-disable-next-line no-duplicate-imports
44
import { JBDateInputWebComponent, type JBDateInputInputTypes, } from 'jb-date-input';
55
import { type ValidationItem } from 'jb-validation/types';
66
import { useEvent } from '../../../common/hooks/use-event';
7-
import { type ValidationValue, type JBDateInputValueObject } from 'jb-date-input/types';
8-
9-
export { type JBDateInputInputTypes, type JBDateInputValueObject };
7+
import { type ValidationValue, type JBDateInputValueObject, type InputType } from 'jb-date-input/types';
8+
// re-export imported types for easier use for user
9+
export { type JBDateInputInputTypes, type JBDateInputValueObject, type ValidationItem, type ValidationValue };
1010
declare global {
1111
// eslint-disable-next-line @typescript-eslint/no-namespace
1212
namespace JSX {
1313
interface IntrinsicElements {
1414
'jb-date-input': JBDateInputType;
1515
}
16-
interface JBDateInputType extends React.DetailedHTMLProps<React.HTMLAttributes<JBDateInputWebComponent>, JBDateInputWebComponent> {
16+
interface JBDateInputType extends DetailedHTMLProps<HTMLAttributes<JBDateInputWebComponent>, JBDateInputWebComponent> {
1717
class?: string,
1818
label?: string,
1919
name?: string,
@@ -32,6 +32,7 @@ export type JBDateInputProps = {
3232
name?: string,
3333
min?: string | null | undefined | Date,
3434
max?: string | null | undefined | Date,
35+
message?: string | null | undefined,
3536
format?: string,
3637
className?: string,
3738
onKeyup?: (e: JBDateInputEventType<KeyboardEvent>) => void,
@@ -43,17 +44,17 @@ export type JBDateInputProps = {
4344
value?: string | Date | null | undefined,
4445
validationList?: ValidationItem<ValidationValue>[],
4546
required?: boolean,
46-
calendarDefaultDateView?: { year: number, month: number, dateType: JBDateInputInputTypes },
47-
usePersianNumber?: boolean,
47+
calendarDefaultDateView?: { year: number, month: number, dateType?: InputType },
48+
showPersianNumber?: boolean,
4849
placeholder?: string | null | undefined,
4950
jalaliMonthList?: string[] | null | undefined,
5051
gregorianMonthList?: string[] | null | undefined,
5152
overflowHandler?:"NONE" | "SLIDE",
52-
overflowRef?:React.RefObject<HTMLElement> | null,
53-
children?: React.ReactNode | React.ReactNode[],
53+
overflowRef?:RefObject<HTMLElement> | null | MutableRefObject<HTMLElement | undefined>,
54+
children?: ReactNode | ReactNode[],
5455
}
5556

56-
export const JBDateInput = React.forwardRef((props: JBDateInputProps, ref) => {
57+
export const JBDateInput = forwardRef((props: JBDateInputProps, ref) => {
5758
const element = useRef<JBDateInputWebComponent>(null);
5859
const [refChangeCount, refChangeCountSetter] = useState(0);
5960
const onFormatChangeCallBackQueueRef = useRef<(() => void)[]>([]);
@@ -125,6 +126,11 @@ export const JBDateInput = React.forwardRef((props: JBDateInputProps, ref) => {
125126
element.current.value = props.value;
126127
}
127128
}, [props.value]);
129+
useEffect(() => {
130+
if (element.current) {
131+
element.current.setAttribute("message",props.message || "");
132+
}
133+
}, [props.message]);
128134
useEffect(() => {
129135
if (element.current && Array.isArray(props.jalaliMonthList)) {
130136
element.current.setMonthList("JALALI", props.jalaliMonthList);
@@ -183,12 +189,12 @@ export const JBDateInput = React.forwardRef((props: JBDateInputProps, ref) => {
183189
}
184190
}, [props.calendarDefaultDateView]);
185191
useEffect(() => {
186-
if (props.usePersianNumber) {
187-
element.current?.setAttribute('use-persian-number', 'true');
192+
if (props.showPersianNumber) {
193+
element.current?.setAttribute('show-persian-number', 'true');
188194
} else {
189-
element.current?.removeAttribute('use-persian-number');
195+
element.current?.removeAttribute('show-persian-number');
190196
}
191-
}, [props.usePersianNumber]);
197+
}, [props.showPersianNumber]);
192198
return (
193199
<jb-date-input class={props.className ? props.className : ""} name={props.name} label={props.label} value-type={props.valueType ? props.valueType : 'GREGORIAN'} ref={element} input-type={props.inputType ? props.inputType : 'JALALI'}>
194200
{props.children}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"react component",
2020
"react"
2121
],
22-
"version": "5.0.0-beta.0",
22+
"version": "5.0.0",
2323
"bugs": "https://github.com/javadbat/jb-date-input-react/issues",
2424
"license": "MIT",
2525
"files": [
@@ -31,12 +31,12 @@
3131
"main": "index.js",
3232
"module": "index.js",
3333
"homepage": "https://github.com/javadbat/jb-date-input-react",
34-
"types": "./dist/jb-date-input/lib/JBDateInput.d.ts",
34+
"types": "./dist/react-component/jb-date-input/lib/JBDateInput.d.ts",
3535
"repository": {
3636
"type": "git",
3737
"url": "https://github.com/javadbat/jb-date-input-react"
3838
},
3939
"dependencies": {
40-
"jb-date-input": ">=5.0.0-beta.0"
40+
"jb-date-input": ">=5.0.0"
4141
}
4242
}

0 commit comments

Comments
 (0)