Skip to content

Commit c58b55f

Browse files
authored
Update DatePicker (#548)
* Clean Try * Update DatePicker.tsx * Update Example * Set version number back * Update yarn.lock * Update yarn.lock
1 parent e712c85 commit c58b55f

File tree

5 files changed

+293
-141
lines changed

5 files changed

+293
-141
lines changed

example/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
"dependencies": {
1818
"@draftbit/maps": "^46.4.3",
1919
"@draftbit/ui": "^46.4.3",
20+
"@expo/dev-server": "0.1.120",
2021
"@expo/webpack-config": "^0.17.0",
2122
"@react-navigation/drawer": "^5.7.7",
2223
"@react-navigation/native": "^5.4.2",
2324
"@shopify/flash-list": "1.2.0",
24-
"expo": "~46.0.7",
25+
"expo": "^46.0.7",
2526
"expo-app-loading": "~2.1.0",
2627
"expo-font": "~10.2.0",
2728
"expo-status-bar": "~1.4.0",
@@ -35,7 +36,7 @@
3536
"react-native-web": "~0.18.7"
3637
},
3738
"devDependencies": {
38-
"@babel/core": "^7.12.9",
39+
"@babel/core": "^7.20.5",
3940
"@types/react": "18.0.0",
4041
"@types/react-native": "0.69.5"
4142
}

example/src/DatePickerExample.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,45 @@ function DatePickerExample({ theme }) {
109109
defaultValue={new Date(DATE_STRING)}
110110
/>
111111
</Section>
112+
<Section title="Styled">
113+
<DatePicker
114+
label={'Date'}
115+
mode={'date'}
116+
style={{
117+
backgroundColor: 'red',
118+
fontFamily: 'AbrilFatface_400Regular',
119+
fontSize: 22,
120+
paddingBottom: 16,
121+
paddingTop: 16,
122+
}}
123+
date={date2}
124+
onDateChange={setDate2}
125+
defaultValue={new Date(DATE_STRING)}
126+
leftIconMode={'inset'}
127+
type={'solid'}
128+
/>
129+
<DatePicker
130+
label={'Date'}
131+
mode={'time'}
132+
style={{
133+
backgroundColor: 'black',
134+
fontFamily: 'AbrilFatface_400Regular',
135+
fontSize: 26,
136+
color: `white`,
137+
paddingBottom: 16,
138+
paddingTop: 16,
139+
}}
140+
date={date3}
141+
onDateChange={setDate3}
142+
defaultValue={new Date(DATE_STRING)}
143+
labelSize={26}
144+
labelColor={'blue'}
145+
borderColor={'blue'}
146+
borderColorActive={'green'}
147+
leftIconMode={'inset'}
148+
type={'underline'}
149+
/>
150+
</Section>
112151
</Container>
113152
);
114153
}

packages/core/src/components/DatePicker/DatePicker.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import DateTimePicker from "./DatePickerComponent";
2323

2424
import type { Theme } from "../../styles/DefaultTheme";
2525
import type { IconSlot } from "../../interfaces/Icon";
26+
import { extractStyles } from "../../utilities";
2627

2728
const AnimatedText = Animated.createAnimatedComponent(Text);
2829

@@ -31,14 +32,13 @@ const BLUR_ANIMATION_DURATION = 180;
3132
const ICON_SIZE = 24;
3233

3334
type Props = {
34-
style?: StyleProp<ViewStyle> & { height?: number };
35+
style?: StyleProp<ViewStyle | TextStyle> & { height?: number };
3536
theme: Theme;
3637
// initialDate?: string;
3738
// locale?: string;
3839
// minuteInterval?: number;
3940
// timeZoneOffsetInMinutes?: number;
4041
// error?: boolean;
41-
// type?: string;
4242
date?: Date;
4343
format?: string;
4444
onDateChange?: (data?: Date) => void;
@@ -47,10 +47,14 @@ type Props = {
4747
mode?: "date" | "time" | "datetime";
4848
type?: "solid" | "underline";
4949
label?: string;
50+
labelSize?: number;
51+
labelColor?: string;
5052
placeholder?: string;
5153
leftIconName?: string;
5254
leftIconMode?: "outset" | "inset";
5355
rightIconName?: string;
56+
borderColor?: string;
57+
borderColorActive?: string;
5458
} & IconSlot &
5559
TextInputProps;
5660

@@ -84,7 +88,11 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
8488
rightIconName,
8589
leftIconMode = "inset",
8690
label,
91+
labelSize,
92+
labelColor,
8793
placeholder,
94+
borderColor: inputBorderColor,
95+
borderColorActive: inputBorderColorActive,
8896
...props
8997
}) => {
9098
const [value, setValue] = React.useState<any>(date || defaultValue);
@@ -106,6 +114,8 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
106114
width: number;
107115
}>({ measured: false, width: 0 });
108116

117+
const { viewStyles, textStyles } = extractStyles(style);
118+
109119
const getValidDate = (): Date => {
110120
if (!value) {
111121
return new Date();
@@ -211,8 +221,11 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
211221

212222
const MINIMIZED_LABEL_Y_OFFSET = -(typography.caption.lineHeight + 4);
213223
const OUTLINE_MINIMIZED_LABEL_Y_OFFSET = -(16 * 0.5 + 4);
214-
const MAXIMIZED_LABEL_FONT_SIZE = typography.subtitle1.fontSize;
215-
const MINIMIZED_LABEL_FONT_SIZE = typography.caption.fontSize;
224+
const MAXIMIZED_LABEL_FONT_SIZE =
225+
textStyles.fontSize || typography.subtitle1.fontSize;
226+
const MINIMIZED_LABEL_FONT_SIZE = labelSize
227+
? labelSize
228+
: typography.caption.fontSize;
216229

217230
const hasActiveOutline = focused;
218231

@@ -233,9 +246,9 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
233246
underlineColor = "transparent";
234247
backgroundColor = colors.divider;
235248
} else {
236-
activeColor = colors.primary;
237-
placeholderColor = borderColor = colors.light;
238-
underlineColor = colors.light;
249+
activeColor = inputBorderColorActive || colors.primary;
250+
placeholderColor = inputBorderColor || colors.light;
251+
underlineColor = inputBorderColor || colors.light;
239252
backgroundColor = colors.background;
240253
}
241254

@@ -306,6 +319,7 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
306319
const labelStyle = {
307320
...typography.subtitle1,
308321
top: type === "solid" ? 16 : 0,
322+
fontFamily: textStyles?.fontFamily,
309323
left:
310324
leftIconName && leftIconMode === "inset"
311325
? ICON_SIZE + (type === "solid" ? 16 : 12)
@@ -364,7 +378,11 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
364378
<Icon {...leftIconProps} style={leftIconStyle} />
365379
) : null}
366380
<View
367-
style={[containerStyle, style ? { height: style.height } : {}]}
381+
style={[
382+
containerStyle,
383+
style ? { height: style.height } : {},
384+
viewStyles,
385+
]}
368386
>
369387
{type === "underline" ? (
370388
// When type === 'flat', render an underline
@@ -406,7 +424,7 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
406424
type === "solid" ? { paddingHorizontal: 12 } : {},
407425
labelStyle,
408426
{
409-
color: colors.light,
427+
color: labelColor || colors.light,
410428
opacity: labeled.interpolate({
411429
inputRange: [0, 1],
412430
outputRange: [hasActiveOutline ? 1 : 0, 0],
@@ -423,7 +441,7 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
423441
type === "solid" ? { paddingHorizontal: 12 } : {},
424442
labelStyle,
425443
{
426-
color: placeholderColor,
444+
color: labelColor || placeholderColor,
427445
opacity: hasActiveOutline ? labeled : 1,
428446
},
429447
]}
@@ -453,7 +471,7 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
453471
onFocus={_handleFocus}
454472
onBlur={_handleBlur}
455473
underlineColorAndroid={"transparent"}
456-
style={inputStyles}
474+
style={[inputStyles, textStyles]}
457475
{...props}
458476
/>
459477
</View>

packages/core/src/mappings/DatePicker.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@ import {
55
FIELD_NAME,
66
GROUPS,
77
Triggers,
8+
StylesPanelSections,
9+
createNumberProp,
10+
createColorProp,
811
} from "@draftbit/types";
912

1013
const SEED_DATA_PROPS = {
11-
label: {
12-
label: "Label",
13-
description: "The label to be displayed on the picker",
14-
formType: FORM_TYPES.string,
15-
propType: PROP_TYPES.STRING,
16-
defaultValue: "Date",
17-
editable: true,
18-
required: true,
19-
group: GROUPS.data,
20-
},
2114
mode: {
2215
label: "Mode",
2316
description: "Choose between date, time and datetime",
@@ -29,6 +22,28 @@ const SEED_DATA_PROPS = {
2922
options: ["date", "time", "datetime"],
3023
group: GROUPS.basic,
3124
},
25+
label: {
26+
label: "Label",
27+
description: "The label to be displayed on the picker",
28+
formType: FORM_TYPES.string,
29+
propType: PROP_TYPES.STRING,
30+
defaultValue: "Date",
31+
editable: true,
32+
required: true,
33+
group: GROUPS.data,
34+
},
35+
labelSize: createNumberProp({
36+
label: "Label Size",
37+
}),
38+
labelColor: createColorProp({
39+
label: "Label Color",
40+
}),
41+
borderColor: createColorProp({
42+
label: "Border Color",
43+
}),
44+
borderColorActive: createColorProp({
45+
label: "Border Color",
46+
}),
3247
format: {
3348
label: "Format",
3449
description: "Create an output format for the date.",
@@ -150,6 +165,13 @@ export const SEED_DATA = [
150165
category: COMPONENT_TYPES.input,
151166
layout: null,
152167
triggers: [Triggers.OnDateChange],
168+
StylesPanelSections: [
169+
StylesPanelSections.Typography,
170+
StylesPanelSections.Background,
171+
StylesPanelSections.Size,
172+
StylesPanelSections.MarginsAndPaddings,
173+
StylesPanelSections.Position,
174+
],
153175
props: {
154176
...SEED_DATA_PROPS,
155177
type: {

0 commit comments

Comments
 (0)