@vectara/vectara-ui 16.11.0 → 16.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { BasicProps as DatePickerProps } from "./DatePicker";
2
2
  import { Props as PopoverProps } from "../popover/Popover";
3
+ import { JSXElementConstructor, ReactElement } from "react";
3
4
  type DateProps = Pick<DatePickerProps, "placeholder" | "data-testid">;
4
5
  type Props = Pick<PopoverProps, "isOpen" | "setIsOpen" | "anchorSide" | "header"> & {
5
6
  startDate?: Date;
@@ -8,7 +9,8 @@ type Props = Pick<PopoverProps, "isOpen" | "setIsOpen" | "anchorSide" | "header"
8
9
  dateRangeProps?: DateProps;
9
10
  fullWidth?: boolean;
10
11
  canClear?: boolean;
12
+ input?: ReactElement<any, string | JSXElementConstructor<any>>;
11
13
  "data-testid"?: string;
12
14
  };
13
- export declare const VuiDateRangePicker: ({ setIsOpen, startDate, endDate, onChange, dateRangeProps, fullWidth, canClear, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const VuiDateRangePicker: ({ setIsOpen, startDate, endDate, onChange, dateRangeProps, fullWidth, canClear, input, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
14
16
  export {};
@@ -16,7 +16,7 @@ import { formatDate } from "../../utils";
16
16
  import { useEffect, useState } from "react";
17
17
  import { VuiCalendar } from "./Calendar";
18
18
  export const VuiDateRangePicker = (_a) => {
19
- var { setIsOpen, startDate, endDate, onChange, dateRangeProps, fullWidth, canClear } = _a, rest = __rest(_a, ["setIsOpen", "startDate", "endDate", "onChange", "dateRangeProps", "fullWidth", "canClear"]);
19
+ var { setIsOpen, startDate, endDate, onChange, dateRangeProps, fullWidth, canClear, input } = _a, rest = __rest(_a, ["setIsOpen", "startDate", "endDate", "onChange", "dateRangeProps", "fullWidth", "canClear", "input"]);
20
20
  const [initialStartDate, setInitialStartDate] = useState();
21
21
  const [initialEndDate, setInitialEndDate] = useState();
22
22
  // When the startDate or endDate props change, update the internal state.
@@ -42,7 +42,7 @@ export const VuiDateRangePicker = (_a) => {
42
42
  const humanizedStartDate = initialStartDate ? formatDate(initialStartDate) : "Unselected start date";
43
43
  const humanizedEndDate = initialEndDate ? formatDate(initialEndDate) : "unselected end date";
44
44
  const { "data-testid": testId } = rest, restProps = __rest(rest, ["data-testid"]);
45
- const input = (_jsx(VuiTextInput, { className: "vuiDateRangePickerInput", value: !initialStartDate && !initialEndDate ? "Select date range" : `${humanizedStartDate} to ${humanizedEndDate}`, fullWidth: fullWidth, "data-testid": testId }));
45
+ const inputEl = input !== null && input !== void 0 ? input : (_jsx(VuiTextInput, { className: "vuiDateRangePickerInput", value: !initialStartDate && !initialEndDate ? "Select date range" : `${humanizedStartDate} to ${humanizedEndDate}`, fullWidth: fullWidth, "data-testid": testId }));
46
46
  return (_jsx(VuiPopover, Object.assign({ setIsOpen: (isOpen) => {
47
47
  if (isOpen) {
48
48
  // Set temporary internal state to the provided values when opening the popover.
@@ -54,5 +54,5 @@ export const VuiDateRangePicker = (_a) => {
54
54
  onChange === null || onChange === void 0 ? void 0 : onChange(initialStartDate, initialEndDate);
55
55
  }
56
56
  setIsOpen(isOpen);
57
- }, button: input }, restProps, { children: dateRangePicker })));
57
+ }, button: inputEl }, restProps, { children: dateRangePicker })));
58
58
  };
@@ -1,4 +1,4 @@
1
- declare const SIZE: readonly ["m", "l"];
1
+ declare const SIZE: readonly ["s", "m", "l"];
2
2
  export type BasicInputProps = Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "size" | "autoComplete" | "ref"> & {
3
3
  isInvalid?: boolean;
4
4
  size?: (typeof SIZE)[number];
@@ -8,7 +8,7 @@ export type BasicInputProps = Omit<React.DetailedHTMLProps<React.InputHTMLAttrib
8
8
  };
9
9
  export declare const VuiBasicInput: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref" | "size" | "autoComplete"> & {
10
10
  isInvalid?: boolean | undefined;
11
- size?: "m" | "l" | undefined;
11
+ size?: "s" | "m" | "l" | undefined;
12
12
  fullWidth?: boolean | undefined;
13
13
  autoComplete?: string | boolean | undefined;
14
14
  isSelected?: boolean | undefined;
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import classNames from "classnames";
14
14
  import { forwardRef } from "react";
15
- const SIZE = ["m", "l"];
15
+ const SIZE = ["s", "m", "l"];
16
16
  export const VuiBasicInput = forwardRef((_a, ref) => {
17
17
  var { className, id, name, placeholder, size = "m", fullWidth, onSubmit, isInvalid, autoFocus, autoComplete, isSelected, onChange = () => undefined } = _a, rest = __rest(_a, ["className", "id", "name", "placeholder", "size", "fullWidth", "onSubmit", "isInvalid", "autoFocus", "autoComplete", "isSelected", "onChange"]);
18
18
  const classes = classNames("vuiInput", `vuiInput--${size}`, {
@@ -1,6 +1,6 @@
1
1
  export declare const VuiPasswordInput: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref" | "size" | "autoComplete"> & {
2
2
  isInvalid?: boolean | undefined;
3
- size?: "m" | "l" | undefined;
3
+ size?: "s" | "m" | "l" | undefined;
4
4
  fullWidth?: boolean | undefined;
5
5
  autoComplete?: string | boolean | undefined;
6
6
  isSelected?: boolean | undefined;
@@ -6,7 +6,7 @@ export type Props = BasicInputProps & {
6
6
  };
7
7
  export declare const VuiTextInput: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref" | "size" | "autoComplete"> & {
8
8
  isInvalid?: boolean | undefined;
9
- size?: "m" | "l" | undefined;
9
+ size?: "s" | "m" | "l" | undefined;
10
10
  fullWidth?: boolean | undefined;
11
11
  autoComplete?: string | boolean | undefined;
12
12
  isSelected?: boolean | undefined;
@@ -5,6 +5,11 @@
5
5
  background-color: var(--vui-color-empty-shade);
6
6
  }
7
7
 
8
+ .vuiInput--s {
9
+ padding: $sizeXs * 0.75 $sizeS;
10
+ font-size: $fontSizeSmall;
11
+ }
12
+
8
13
  .vuiInput--m {
9
14
  padding: $sizeXs $sizeM;
10
15
  font-size: $fontSizeStandard;
@@ -2848,6 +2848,11 @@ h2.react-datepicker__current-month {
2848
2848
  background-color: var(--vui-color-empty-shade);
2849
2849
  }
2850
2850
 
2851
+ .vuiInput--s {
2852
+ padding: 6px 12px;
2853
+ font-size: 12px;
2854
+ }
2855
+
2851
2856
  .vuiInput--m {
2852
2857
  padding: 8px 16px;
2853
2858
  font-size: 14px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectara/vectara-ui",
3
- "version": "16.11.0",
3
+ "version": "16.12.0",
4
4
  "homepage": "./",
5
5
  "description": "Vectara's design system, codified as a React and Sass component library",
6
6
  "author": "Vectara",
@@ -8,7 +8,7 @@ type Props = {
8
8
  export const Subsection = ({ title, children }: Props) => {
9
9
  return (
10
10
  <>
11
- <VuiTitle size="s">
11
+ <VuiTitle size="xs">
12
12
  <h4>{title}</h4>
13
13
  </VuiTitle>
14
14
 
@@ -0,0 +1,66 @@
1
+ import { useState } from "react";
2
+ import { VuiButtonSecondary, VuiDateRangePicker, VuiSpacer, VuiText, VuiTextInput } from "../../../lib";
3
+ import { formatDate } from "../../../lib/utils";
4
+
5
+ export const DateRangePickerCustomInput = () => {
6
+ const [isOpen, setIsOpen] = useState<boolean>(false);
7
+ const [startDate, setStartDate] = useState<Date | undefined>(
8
+ new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000)
9
+ );
10
+ const [endDate, setEndDate] = useState<Date | undefined>(undefined);
11
+
12
+ const humanizedStartDate = startDate ? formatDate(startDate) : "Unselected start date";
13
+ const humanizedEndDate = endDate ? formatDate(endDate) : "unselected end date";
14
+
15
+ return (
16
+ <>
17
+ <VuiText>
18
+ <p>
19
+ From {startDate?.toUTCString() ?? "unknown"} to {endDate?.toUTCString() ?? "unknown"}
20
+ </p>
21
+ </VuiText>
22
+
23
+ <VuiSpacer size="s" />
24
+
25
+ <VuiButtonSecondary
26
+ color="neutral"
27
+ onClick={() => {
28
+ // Add one day to the end date.
29
+ setEndDate((prevEndDate) => {
30
+ if (!prevEndDate) return new Date();
31
+ const newEndDate = new Date(prevEndDate);
32
+ newEndDate.setDate(newEndDate.getDate() + 1);
33
+ return newEndDate;
34
+ });
35
+ }}
36
+ >
37
+ Add day to verify external control
38
+ </VuiButtonSecondary>
39
+
40
+ <VuiSpacer size="s" />
41
+
42
+ <VuiDateRangePicker
43
+ header="Date filter"
44
+ startDate={startDate}
45
+ endDate={endDate}
46
+ onChange={(startDate, endDate) => {
47
+ setStartDate(startDate);
48
+ setEndDate(endDate);
49
+ }}
50
+ isOpen={isOpen}
51
+ setIsOpen={setIsOpen}
52
+ anchorSide="left"
53
+ data-testid="dateRangePickerButton"
54
+ dateRangeProps={{ "data-testid": "dateRangePicker" }}
55
+ canClear
56
+ input={
57
+ <VuiTextInput
58
+ size="s"
59
+ className="vuiDateRangePickerInput"
60
+ value={!startDate && !endDate ? "Select date range" : `${humanizedStartDate} to ${humanizedEndDate}`}
61
+ />
62
+ }
63
+ />
64
+ </>
65
+ );
66
+ };
@@ -1,11 +1,13 @@
1
1
  import { DatePicker } from "./DatePicker";
2
2
  import { Inline } from "./Inline";
3
3
  import { DateRangePicker } from "./DateRangePicker";
4
+ import { DateRangePickerCustomInput } from "./DateRangePickerCustomInput";
4
5
  import { WithTimeSelection } from "./WithTimeSelection";
5
6
 
6
7
  const DatePickerSource = require("!!raw-loader!./DatePicker");
7
8
  const InlineSource = require("!!raw-loader!./Inline");
8
9
  const DateRangePickerSource = require("!!raw-loader!./DateRangePicker");
10
+ const DateRangePickerCustomInputSource = require("!!raw-loader!./DateRangePickerCustomInput");
9
11
  const WithTimeSelectionSource = require("!!raw-loader!./WithTimeSelection");
10
12
 
11
13
  export const datePicker = {
@@ -27,6 +29,11 @@ export const datePicker = {
27
29
  component: <DateRangePicker />,
28
30
  source: DateRangePickerSource.default.toString()
29
31
  },
32
+ {
33
+ name: "Date range with custom input",
34
+ component: <DateRangePickerCustomInput />,
35
+ source: DateRangePickerCustomInputSource.default.toString()
36
+ },
30
37
  {
31
38
  name: "With time selection",
32
39
  component: <WithTimeSelection />,
@@ -0,0 +1,47 @@
1
+ import { useState } from "react";
2
+ import { VuiTextInput } from "../../../lib";
3
+ import { Subsection } from "../../components/Subsection";
4
+
5
+ export const Sizes = () => {
6
+ const [value, setValue] = useState<string | undefined>();
7
+
8
+ return (
9
+ <>
10
+ <Subsection title="Large">
11
+ <VuiTextInput
12
+ size="l"
13
+ id="textInput"
14
+ name="text"
15
+ placeholder="Type something…"
16
+ value={value}
17
+ onSubmit={() => alert("Submit")}
18
+ onChange={(event) => setValue(event.target.value)}
19
+ />
20
+ </Subsection>
21
+
22
+ <Subsection title="Medium">
23
+ <VuiTextInput
24
+ size="m"
25
+ id="textInput"
26
+ name="text"
27
+ placeholder="Type something…"
28
+ value={value}
29
+ onSubmit={() => alert("Submit")}
30
+ onChange={(event) => setValue(event.target.value)}
31
+ />
32
+ </Subsection>
33
+
34
+ <Subsection title="Small">
35
+ <VuiTextInput
36
+ size="s"
37
+ id="textInput"
38
+ name="text"
39
+ placeholder="Type something…"
40
+ value={value}
41
+ onSubmit={() => alert("Submit")}
42
+ onChange={(event) => setValue(event.target.value)}
43
+ />
44
+ </Subsection>
45
+ </>
46
+ );
47
+ };
@@ -2,13 +2,13 @@ import { TextInput } from "./TextInput";
2
2
  import { NumberInput } from "./NumberInput";
3
3
  import { PasswordInput } from "./PasswordInput";
4
4
  import { FullWidth } from "./FullWidth";
5
- import { Large } from "./Large";
5
+ import { Sizes } from "./Sizes";
6
6
 
7
7
  const TextInputSource = require("!!raw-loader!./TextInput");
8
8
  const NumberInputSource = require("!!raw-loader!./NumberInput");
9
9
  const PasswordInputSource = require("!!raw-loader!./PasswordInput");
10
10
  const FullWidthSource = require("!!raw-loader!./FullWidth");
11
- const LargeSource = require("!!raw-loader!./Large");
11
+ const SizesSource = require("!!raw-loader!./Sizes");
12
12
 
13
13
  export const input = {
14
14
  name: "Input",
@@ -35,9 +35,9 @@ export const input = {
35
35
  source: FullWidthSource.default.toString()
36
36
  },
37
37
  {
38
- name: "Large size",
39
- component: <Large />,
40
- source: LargeSource.default.toString()
38
+ name: "Sizes",
39
+ component: <Sizes />,
40
+ source: SizesSource.default.toString()
41
41
  }
42
42
  ]
43
43
  };
@@ -13,7 +13,7 @@ export const searchInput = {
13
13
  path: "/searchInput",
14
14
  examples: [
15
15
  {
16
- name: "Medium size",
16
+ name: "Sizes",
17
17
  component: <SearchInput />,
18
18
  source: SearchInputSource.default.toString()
19
19
  },
@@ -1,18 +0,0 @@
1
- import { useState } from "react";
2
- import { VuiTextInput } from "../../../lib";
3
-
4
- export const Large = () => {
5
- const [value, setValue] = useState<string | undefined>();
6
-
7
- return (
8
- <VuiTextInput
9
- size="l"
10
- id="textInput"
11
- name="text"
12
- placeholder="Type something…"
13
- value={value}
14
- onSubmit={() => alert("Submit")}
15
- onChange={(event) => setValue(event.target.value)}
16
- />
17
- );
18
- };