@ilo-org/react 0.10.5 → 0.10.6

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @ilo-org/react
2
2
 
3
+ ## 0.10.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 460210518: Add clear button to search input field
8
+ - Updated dependencies [ac23bf484]
9
+ - Updated dependencies [1b9c54f99]
10
+ - Updated dependencies [138890e7a]
11
+ - @ilo-org/styles@0.14.0
12
+
3
13
  ## 0.10.5
4
14
 
5
15
  ### Patch Changes
@@ -11,7 +11,7 @@ require('../../GlobalCtx-97e4b433.js');
11
11
  require('../Tooltip/Tooltip.js');
12
12
  require('@popperjs/core');
13
13
 
14
- const Input = ({ callback, disabled = false, error, helper, id, label, name, placeholder, required, tooltip, type = "text", }) => {
14
+ const Input = ({ callback, disabled = false, error, helper, id, label, name, placeholder, required, tooltip, value, type = "text", }) => {
15
15
  const { prefix } = hooks_useGlobalSettings();
16
16
  const baseClass = `${prefix}--input`;
17
17
  const InputClasses = classNames("", {
@@ -26,7 +26,7 @@ const Input = ({ callback, disabled = false, error, helper, id, label, name, pla
26
26
  callback(e);
27
27
  }
28
28
  };
29
- return (jsxRuntime.jsx(components_Fieldset_Fieldset.default, { children: jsxRuntime.jsx(components_FormElement_FormElement, Object.assign({ elemid: name, label: label, helper: helper, error: error, required: required, tooltip: tooltip }, { children: jsxRuntime.jsx("input", { id: id ? id : name, name: name, onChange: handleChange, disabled: disabled, placeholder: placeholder, required: required, type: type, className: InputClasses }) })) }));
29
+ return (jsxRuntime.jsx(components_Fieldset_Fieldset.default, { children: jsxRuntime.jsx(components_FormElement_FormElement, Object.assign({ elemid: name, label: label, helper: helper, error: error, required: required, tooltip: tooltip }, { children: jsxRuntime.jsx("input", { id: id ? id : name, name: name, onChange: handleChange, disabled: disabled, placeholder: placeholder, required: required, type: type, value: value, className: InputClasses }) })) }));
30
30
  };
31
31
 
32
32
  module.exports = Input;
@@ -13,6 +13,8 @@ require('../Fieldset/Fieldset.js');
13
13
  require('../Tooltip/Tooltip.js');
14
14
  require('@popperjs/core');
15
15
  require('../FormElement/FormElement.js');
16
+ require('../Icon/Icon.js');
17
+ require('@ilo-org/icons-react');
16
18
 
17
19
  const Navigation = ({ logo, mobilelogo, siteurl, tagline, primarynav, subnav, menulabel, menucloselabel, searchlabel, searchfield, languagelabel, languagecontextmenu, }) => {
18
20
  const { prefix } = hooks_useGlobalSettings();
@@ -14,6 +14,8 @@ require('../Fieldset/Fieldset.js');
14
14
  require('../Tooltip/Tooltip.js');
15
15
  require('@popperjs/core');
16
16
  require('../FormElement/FormElement.js');
17
+ require('../Icon/Icon.js');
18
+ require('@ilo-org/icons-react');
17
19
 
18
20
 
19
21
 
@@ -1,38 +1,48 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
+ var require$$0 = require('react');
4
5
  var classNames = require('classnames');
5
6
  var hooks_useGlobalSettings = require('../../hooks/useGlobalSettings.js');
6
7
  var components_Input_Input = require('../Input/Input.js');
8
+ var components_Icon_Icon = require('../Icon/Icon.js');
7
9
  require('tslib');
8
- require('react');
9
10
  require('../../GlobalCtx-97e4b433.js');
10
11
  require('../Fieldset/Fieldset.js');
11
12
  require('../Tooltip/Tooltip.js');
12
13
  require('@popperjs/core');
13
14
  require('../FormElement/FormElement.js');
15
+ require('@ilo-org/icons-react');
14
16
 
15
17
  const SearchField = ({ action, callback, className, input, }) => {
18
+ const [searchValue, setSearchValue] = require$$0.useState("");
16
19
  const { prefix } = hooks_useGlobalSettings();
17
20
  const baseClass = `${prefix}--searchfield`;
18
21
  const buttonClass = `${baseClass}--button`;
22
+ const clearButtonClass = `${baseClass}--clear-button ${searchValue.trim() !== "" && "show"}`;
23
+ const fieldSetClass = `${prefix}--fieldset`;
19
24
  const SearchFieldClasses = classNames(className, {
20
25
  [baseClass]: true,
21
26
  [`haslabel`]: input === null || input === void 0 ? void 0 : input.label,
22
27
  });
23
- /**
24
- * On click, if there is a callback, call it
25
- */
26
28
  const handleClick = (e) => {
27
29
  if (callback) {
28
30
  callback(e);
29
31
  }
30
32
  };
33
+ // handle click for clear button in search
34
+ const handleClearButtonClick = () => {
35
+ setSearchValue("");
36
+ };
37
+ // Update search value on input
38
+ const onKeyPress = (e) => {
39
+ setSearchValue(e.target.value);
40
+ };
31
41
  const inputHasType = !!(input === null || input === void 0 ? void 0 : input.type);
32
42
  if (!inputHasType) {
33
43
  throw new Error("SearchField: Input must have type prop");
34
44
  }
35
- return inputHasType ? (jsxRuntime.jsxs("form", Object.assign({ className: SearchFieldClasses, action: action }, { children: [jsxRuntime.jsx(components_Input_Input, { id: input === null || input === void 0 ? void 0 : input.id, name: input === null || input === void 0 ? void 0 : input.name, disabled: input === null || input === void 0 ? void 0 : input.disabled, callback: input === null || input === void 0 ? void 0 : input.callback, error: input === null || input === void 0 ? void 0 : input.error, helper: input === null || input === void 0 ? void 0 : input.helper, label: input === null || input === void 0 ? void 0 : input.label, placeholder: input === null || input === void 0 ? void 0 : input.placeholder, type: input === null || input === void 0 ? void 0 : input.type, className: `${prefix}--input` }), jsxRuntime.jsx("input", { className: buttonClass, disabled: input === null || input === void 0 ? void 0 : input.disabled, type: "submit", onClick: handleClick })] }))) : null;
45
+ return inputHasType ? (jsxRuntime.jsxs("form", Object.assign({ className: SearchFieldClasses, action: action }, { children: [jsxRuntime.jsxs("div", Object.assign({ className: fieldSetClass }, { children: [jsxRuntime.jsx(components_Input_Input, { id: input === null || input === void 0 ? void 0 : input.id, name: input === null || input === void 0 ? void 0 : input.name, disabled: input === null || input === void 0 ? void 0 : input.disabled, callback: onKeyPress, error: input === null || input === void 0 ? void 0 : input.error, helper: input === null || input === void 0 ? void 0 : input.helper, label: input === null || input === void 0 ? void 0 : input.label, placeholder: input === null || input === void 0 ? void 0 : input.placeholder, type: input === null || input === void 0 ? void 0 : input.type, value: searchValue, className: `${prefix}--input` }), jsxRuntime.jsx("span", Object.assign({ onClick: handleClearButtonClick, className: clearButtonClass }, { children: jsxRuntime.jsx(components_Icon_Icon, { name: "close", hidden: true }) }))] })), jsxRuntime.jsx("input", { className: buttonClass, disabled: input === null || input === void 0 ? void 0 : input.disabled, type: "submit", onClick: handleClick })] }))) : null;
36
46
  };
37
47
 
38
48
  module.exports = SearchField;
@@ -2,16 +2,18 @@
2
2
 
3
3
  var components_SearchField_SearchField = require('./SearchField.js');
4
4
  require('react/jsx-runtime');
5
+ require('react');
5
6
  require('classnames');
6
7
  require('../../hooks/useGlobalSettings.js');
7
8
  require('tslib');
8
- require('react');
9
9
  require('../../GlobalCtx-97e4b433.js');
10
10
  require('../Input/Input.js');
11
11
  require('../Fieldset/Fieldset.js');
12
12
  require('../Tooltip/Tooltip.js');
13
13
  require('@popperjs/core');
14
14
  require('../FormElement/FormElement.js');
15
+ require('../Icon/Icon.js');
16
+ require('@ilo-org/icons-react');
15
17
 
16
18
 
17
19
 
@@ -9,7 +9,7 @@ import '../../GlobalCtx-7fb23cfa.js';
9
9
  import '../Tooltip/Tooltip.js';
10
10
  import '@popperjs/core';
11
11
 
12
- const Input = ({ callback, disabled = false, error, helper, id, label, name, placeholder, required, tooltip, type = "text", }) => {
12
+ const Input = ({ callback, disabled = false, error, helper, id, label, name, placeholder, required, tooltip, value, type = "text", }) => {
13
13
  const { prefix } = useGlobalSettings();
14
14
  const baseClass = `${prefix}--input`;
15
15
  const InputClasses = classNames("", {
@@ -24,7 +24,7 @@ const Input = ({ callback, disabled = false, error, helper, id, label, name, pla
24
24
  callback(e);
25
25
  }
26
26
  };
27
- return (jsx(Fieldset, { children: jsx(FormElement, Object.assign({ elemid: name, label: label, helper: helper, error: error, required: required, tooltip: tooltip }, { children: jsx("input", { id: id ? id : name, name: name, onChange: handleChange, disabled: disabled, placeholder: placeholder, required: required, type: type, className: InputClasses }) })) }));
27
+ return (jsx(Fieldset, { children: jsx(FormElement, Object.assign({ elemid: name, label: label, helper: helper, error: error, required: required, tooltip: tooltip }, { children: jsx("input", { id: id ? id : name, name: name, onChange: handleChange, disabled: disabled, placeholder: placeholder, required: required, type: type, value: value, className: InputClasses }) })) }));
28
28
  };
29
29
 
30
30
  export { Input as default };
@@ -11,6 +11,8 @@ import '../Fieldset/Fieldset.js';
11
11
  import '../Tooltip/Tooltip.js';
12
12
  import '@popperjs/core';
13
13
  import '../FormElement/FormElement.js';
14
+ import '../Icon/Icon.js';
15
+ import '@ilo-org/icons-react';
14
16
 
15
17
  const Navigation = ({ logo, mobilelogo, siteurl, tagline, primarynav, subnav, menulabel, menucloselabel, searchlabel, searchfield, languagelabel, languagecontextmenu, }) => {
16
18
  const { prefix } = useGlobalSettings();
@@ -12,3 +12,5 @@ import '../Fieldset/Fieldset.js';
12
12
  import '../Tooltip/Tooltip.js';
13
13
  import '@popperjs/core';
14
14
  import '../FormElement/FormElement.js';
15
+ import '../Icon/Icon.js';
16
+ import '@ilo-org/icons-react';
@@ -1,36 +1,46 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { useState } from 'react';
2
3
  import classNames from 'classnames';
3
4
  import useGlobalSettings from '../../hooks/useGlobalSettings.js';
4
5
  import Input from '../Input/Input.js';
6
+ import Icon from '../Icon/Icon.js';
5
7
  import 'tslib';
6
- import 'react';
7
8
  import '../../GlobalCtx-7fb23cfa.js';
8
9
  import '../Fieldset/Fieldset.js';
9
10
  import '../Tooltip/Tooltip.js';
10
11
  import '@popperjs/core';
11
12
  import '../FormElement/FormElement.js';
13
+ import '@ilo-org/icons-react';
12
14
 
13
15
  const SearchField = ({ action, callback, className, input, }) => {
16
+ const [searchValue, setSearchValue] = useState("");
14
17
  const { prefix } = useGlobalSettings();
15
18
  const baseClass = `${prefix}--searchfield`;
16
19
  const buttonClass = `${baseClass}--button`;
20
+ const clearButtonClass = `${baseClass}--clear-button ${searchValue.trim() !== "" && "show"}`;
21
+ const fieldSetClass = `${prefix}--fieldset`;
17
22
  const SearchFieldClasses = classNames(className, {
18
23
  [baseClass]: true,
19
24
  [`haslabel`]: input === null || input === void 0 ? void 0 : input.label,
20
25
  });
21
- /**
22
- * On click, if there is a callback, call it
23
- */
24
26
  const handleClick = (e) => {
25
27
  if (callback) {
26
28
  callback(e);
27
29
  }
28
30
  };
31
+ // handle click for clear button in search
32
+ const handleClearButtonClick = () => {
33
+ setSearchValue("");
34
+ };
35
+ // Update search value on input
36
+ const onKeyPress = (e) => {
37
+ setSearchValue(e.target.value);
38
+ };
29
39
  const inputHasType = !!(input === null || input === void 0 ? void 0 : input.type);
30
40
  if (!inputHasType) {
31
41
  throw new Error("SearchField: Input must have type prop");
32
42
  }
33
- return inputHasType ? (jsxs("form", Object.assign({ className: SearchFieldClasses, action: action }, { children: [jsx(Input, { id: input === null || input === void 0 ? void 0 : input.id, name: input === null || input === void 0 ? void 0 : input.name, disabled: input === null || input === void 0 ? void 0 : input.disabled, callback: input === null || input === void 0 ? void 0 : input.callback, error: input === null || input === void 0 ? void 0 : input.error, helper: input === null || input === void 0 ? void 0 : input.helper, label: input === null || input === void 0 ? void 0 : input.label, placeholder: input === null || input === void 0 ? void 0 : input.placeholder, type: input === null || input === void 0 ? void 0 : input.type, className: `${prefix}--input` }), jsx("input", { className: buttonClass, disabled: input === null || input === void 0 ? void 0 : input.disabled, type: "submit", onClick: handleClick })] }))) : null;
43
+ return inputHasType ? (jsxs("form", Object.assign({ className: SearchFieldClasses, action: action }, { children: [jsxs("div", Object.assign({ className: fieldSetClass }, { children: [jsx(Input, { id: input === null || input === void 0 ? void 0 : input.id, name: input === null || input === void 0 ? void 0 : input.name, disabled: input === null || input === void 0 ? void 0 : input.disabled, callback: onKeyPress, error: input === null || input === void 0 ? void 0 : input.error, helper: input === null || input === void 0 ? void 0 : input.helper, label: input === null || input === void 0 ? void 0 : input.label, placeholder: input === null || input === void 0 ? void 0 : input.placeholder, type: input === null || input === void 0 ? void 0 : input.type, value: searchValue, className: `${prefix}--input` }), jsx("span", Object.assign({ onClick: handleClearButtonClick, className: clearButtonClass }, { children: jsx(Icon, { name: "close", hidden: true }) }))] })), jsx("input", { className: buttonClass, disabled: input === null || input === void 0 ? void 0 : input.disabled, type: "submit", onClick: handleClick })] }))) : null;
34
44
  };
35
45
 
36
46
  export { SearchField as default };
@@ -1,12 +1,14 @@
1
1
  export { default as SearchField } from './SearchField.js';
2
2
  import 'react/jsx-runtime';
3
+ import 'react';
3
4
  import 'classnames';
4
5
  import '../../hooks/useGlobalSettings.js';
5
6
  import 'tslib';
6
- import 'react';
7
7
  import '../../GlobalCtx-7fb23cfa.js';
8
8
  import '../Input/Input.js';
9
9
  import '../Fieldset/Fieldset.js';
10
10
  import '../Tooltip/Tooltip.js';
11
11
  import '@popperjs/core';
12
12
  import '../FormElement/FormElement.js';
13
+ import '../Icon/Icon.js';
14
+ import '@ilo-org/icons-react';
@@ -48,4 +48,5 @@ export interface InputProps {
48
48
  * The input's type.
49
49
  */
50
50
  type: TextInputTypes;
51
+ value: string;
51
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ilo-org/react",
3
- "version": "0.10.5",
3
+ "version": "0.10.6",
4
4
  "description": "React components for the ILO's Design System",
5
5
  "keywords": [
6
6
  "ui_patterns",
@@ -75,9 +75,9 @@
75
75
  "react-player": "2.10.1",
76
76
  "react-transition-group": "^4.4.1",
77
77
  "@ilo-org/brand-assets": "0.4.0",
78
- "@ilo-org/fonts": "0.1.2",
79
78
  "@ilo-org/icons-react": "0.0.21",
80
- "@ilo-org/styles": "0.13.3",
79
+ "@ilo-org/fonts": "0.1.2",
80
+ "@ilo-org/styles": "0.14.0",
81
81
  "@ilo-org/themes": "0.7.1",
82
82
  "@ilo-org/utils": "0.0.11"
83
83
  },
@@ -132,8 +132,8 @@
132
132
  "tslib": "^2.3.1",
133
133
  "vite": "^4.5.2",
134
134
  "@ilo-org/eslint-config": "0.1.0",
135
- "@ilo-org/prettier-config": "0.0.2",
136
- "@ilo-org/typescript-config": "0.0.1"
135
+ "@ilo-org/typescript-config": "0.0.1",
136
+ "@ilo-org/prettier-config": "0.0.2"
137
137
  },
138
138
  "peerDependencies": {
139
139
  "react": ">16",
@@ -60,4 +60,6 @@ export interface InputProps {
60
60
  * The input's type.
61
61
  */
62
62
  type: TextInputTypes;
63
+
64
+ value: string;
63
65
  }
@@ -16,6 +16,7 @@ const Input: FC<InputProps> = ({
16
16
  placeholder,
17
17
  required,
18
18
  tooltip,
19
+ value,
19
20
  type = "text",
20
21
  }) => {
21
22
  const { prefix } = useGlobalSettings();
@@ -53,6 +54,7 @@ const Input: FC<InputProps> = ({
53
54
  placeholder={placeholder}
54
55
  required={required as any}
55
56
  type={type}
57
+ value={value}
56
58
  className={InputClasses}
57
59
  />
58
60
  </FormElement>
@@ -8,6 +8,7 @@ const searchfield: SearchFieldProps = {
8
8
  name: "search",
9
9
  placeholder: "Search Field",
10
10
  type: "search",
11
+ value: "",
11
12
  },
12
13
  };
13
14
 
@@ -20,6 +21,7 @@ const searchfielderror: SearchFieldProps = {
20
21
  name: "search",
21
22
  placeholder: "Search Field",
22
23
  type: "search",
24
+ value: "",
23
25
  },
24
26
  };
25
27
 
@@ -31,6 +33,7 @@ const searchfielddisabled: SearchFieldProps = {
31
33
  name: "search",
32
34
  placeholder: "Search Field",
33
35
  type: "search",
36
+ value: "",
34
37
  },
35
38
  };
36
39
 
@@ -41,6 +44,7 @@ const searchfieldlabel: SearchFieldProps = {
41
44
  name: "search",
42
45
  placeholder: "Search Field",
43
46
  type: "search",
47
+ value: "",
44
48
  },
45
49
  };
46
50
 
@@ -51,6 +55,7 @@ const searchfieldhelper: SearchFieldProps = {
51
55
  name: "search",
52
56
  placeholder: "Search Field",
53
57
  type: "search",
58
+ value: "",
54
59
  },
55
60
  };
56
61
 
@@ -1,8 +1,9 @@
1
- import { FC } from "react";
1
+ import { FC, useState } from "react";
2
2
  import classNames from "classnames";
3
3
  import useGlobalSettings from "../../hooks/useGlobalSettings";
4
4
  import { SearchFieldProps } from "./SearchField.props";
5
5
  import { Input } from "../Input";
6
+ import { Icon } from "../Icon";
6
7
 
7
8
  const SearchField: FC<SearchFieldProps> = ({
8
9
  action,
@@ -10,24 +11,39 @@ const SearchField: FC<SearchFieldProps> = ({
10
11
  className,
11
12
  input,
12
13
  }) => {
14
+ const [searchValue, setSearchValue] = useState("");
15
+
13
16
  const { prefix } = useGlobalSettings();
14
17
  const baseClass = `${prefix}--searchfield`;
15
18
  const buttonClass = `${baseClass}--button`;
19
+ const clearButtonClass = `${baseClass}--clear-button ${
20
+ searchValue.trim() !== "" && "show"
21
+ }`;
22
+ const fieldSetClass = `${prefix}--fieldset`;
16
23
 
17
24
  const SearchFieldClasses = classNames(className, {
18
25
  [baseClass]: true,
19
26
  [`haslabel`]: input?.label,
20
27
  });
21
28
 
22
- /**
23
- * On click, if there is a callback, call it
24
- */
25
29
  const handleClick: React.MouseEventHandler<HTMLInputElement> = (e) => {
26
30
  if (callback) {
27
31
  callback(e);
28
32
  }
29
33
  };
30
34
 
35
+ // handle click for clear button in search
36
+ const handleClearButtonClick: React.MouseEventHandler<
37
+ HTMLInputElement
38
+ > = () => {
39
+ setSearchValue("");
40
+ };
41
+
42
+ // Update search value on input
43
+ const onKeyPress: React.ChangeEventHandler<HTMLInputElement> = (e) => {
44
+ setSearchValue(e.target.value);
45
+ };
46
+
31
47
  const inputHasType = !!input?.type;
32
48
 
33
49
  if (!inputHasType) {
@@ -36,18 +52,24 @@ const SearchField: FC<SearchFieldProps> = ({
36
52
 
37
53
  return inputHasType ? (
38
54
  <form className={SearchFieldClasses} action={action}>
39
- <Input
40
- id={input?.id}
41
- name={input?.name}
42
- disabled={input?.disabled}
43
- callback={input?.callback}
44
- error={input?.error}
45
- helper={input?.helper}
46
- label={input?.label}
47
- placeholder={input?.placeholder}
48
- type={input?.type}
49
- className={`${prefix}--input`}
50
- />
55
+ <div className={fieldSetClass}>
56
+ <Input
57
+ id={input?.id}
58
+ name={input?.name}
59
+ disabled={input?.disabled}
60
+ callback={onKeyPress}
61
+ error={input?.error}
62
+ helper={input?.helper}
63
+ label={input?.label}
64
+ placeholder={input?.placeholder}
65
+ type={input?.type}
66
+ value={searchValue}
67
+ className={`${prefix}--input`}
68
+ />
69
+ <span onClick={handleClearButtonClick} className={clearButtonClass}>
70
+ <Icon name="close" hidden={true} />
71
+ </span>
72
+ </div>
51
73
  <input
52
74
  className={buttonClass}
53
75
  disabled={input?.disabled}