@bitrise/bitkit 10.8.0 → 10.9.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.
@@ -0,0 +1,52 @@
1
+ import { Children, cloneElement, isValidElement, ReactNode, useEffect, useMemo, useState } from 'react';
2
+ import { chakra } from '@chakra-ui/react';
3
+ import { useDropdownStyles } from '../Dropdown.context';
4
+ import isNodeMatch from '../isNodeMatch';
5
+ import { DropdownGroup } from '../DropdownOption';
6
+
7
+ const NoResultsFound = ({ children }: { children: ReactNode }) => {
8
+ const { item } = useDropdownStyles();
9
+ return <chakra.div __css={item}>{children}</chakra.div>;
10
+ };
11
+ function useSimpleSearch({
12
+ children,
13
+ onSearch,
14
+ isOpen,
15
+ }: {
16
+ children?: ReactNode;
17
+ onSearch?: () => void;
18
+ isOpen: boolean;
19
+ }) {
20
+ const [searchValue, setSearchValue] = useState('');
21
+ const searchOnChange = (newValue: string) => {
22
+ setSearchValue(newValue);
23
+ onSearch?.();
24
+ };
25
+ const options = useMemo(() => {
26
+ if (!searchValue) {
27
+ return children;
28
+ }
29
+
30
+ const transform = (node: ReactNode): ReactNode => {
31
+ if (isValidElement(node) && node.type === DropdownGroup) {
32
+ const groupChildren = Children.toArray(node.props.children).map(transform).filter(Boolean);
33
+ if (groupChildren.length === 0) {
34
+ return null;
35
+ }
36
+ return cloneElement(node, {
37
+ ...node.props,
38
+ children: groupChildren,
39
+ });
40
+ }
41
+ return isNodeMatch(node, searchValue) ? node : null;
42
+ };
43
+
44
+ const results = Children.toArray(children).map(transform).filter(Boolean);
45
+
46
+ return results.length ? results : <NoResultsFound>No results found for `{searchValue}`</NoResultsFound>;
47
+ }, [children, searchValue]);
48
+ useEffect(() => setSearchValue(''), [isOpen]);
49
+
50
+ return { children: options, searchValue, searchOnChange };
51
+ }
52
+ export { useSimpleSearch, NoResultsFound };
@@ -0,0 +1,39 @@
1
+ import React, { JSXElementConstructor, ReactElement, ReactNode } from 'react';
2
+
3
+ type SearchableElement = JSXElementConstructor<any> & { searchable: true };
4
+ export function isSearchable(
5
+ node: string | JSXElementConstructor<any> | SearchableElement,
6
+ ): node is (x: any) => ReactElement {
7
+ return typeof node === 'function' && 'searchable' in node && node.searchable;
8
+ }
9
+
10
+ function isNodeMatch(node: ReactNode, filter: string): boolean {
11
+ if (typeof node === 'number' || typeof node === 'boolean' || typeof node === 'undefined' || node === null) {
12
+ return false;
13
+ }
14
+ if (typeof node === 'string') {
15
+ return node.toLowerCase().includes(filter.toLowerCase());
16
+ }
17
+ if (Array.isArray(node)) {
18
+ return node.some((child) => isNodeMatch(child, filter));
19
+ }
20
+ if ('children' in node) {
21
+ return isNodeMatch(node.children, filter);
22
+ }
23
+ if (React.isValidElement(node)) {
24
+ if (node.type === 'svg') {
25
+ return false;
26
+ }
27
+ const ctor = node.type;
28
+ if (isSearchable(ctor)) {
29
+ return isNodeMatch(ctor(node.props), filter);
30
+ }
31
+ return isNodeMatch(node.props.children, filter);
32
+ }
33
+ if (Symbol.iterator in node) {
34
+ return isNodeMatch(Array.from(node), filter);
35
+ }
36
+ return false;
37
+ }
38
+
39
+ export default isNodeMatch;
@@ -0,0 +1,19 @@
1
+ import { SystemStyleObject } from '@chakra-ui/react';
2
+
3
+ const InputTheme = {
4
+ baseStyle: {
5
+ field: <SystemStyleObject>{
6
+ height: '48',
7
+ borderRadius: '4',
8
+ borderStyle: 'solid',
9
+ borderWidth: '1px',
10
+ boxShadow: 'inner',
11
+ _focusVisible: {
12
+ boxShadow: 'outline',
13
+ outline: 'none',
14
+ },
15
+ },
16
+ },
17
+ };
18
+
19
+ export default InputTheme;
package/src/theme.ts CHANGED
@@ -13,6 +13,8 @@ import List from './Components/List/List.theme';
13
13
  import Menu from './Components/Menu/Menu.theme';
14
14
  import Radio from './Components/Form/Radio/Radio.theme';
15
15
  import Select from './Components/Select/Select.theme';
16
+ import Input from './Components/Input/Input.theme';
17
+ import Dropdown from './Components/Dropdown/Dropdown.theme';
16
18
  import Tabs from './Components/Tabs/Tabs.theme';
17
19
  import Text from './Components/Text/Text.theme';
18
20
  import Alert from './Foundations/Themes/Alert.theme';
@@ -79,11 +81,13 @@ const theme = {
79
81
  Modal: Dialog,
80
82
  Radio,
81
83
  Select,
84
+ Dropdown,
82
85
  Tabs,
83
86
  Text,
84
87
  Tooltip,
85
88
  Alert,
86
89
  CloseButton,
90
+ Input,
87
91
  Popover,
88
92
  },
89
93
  };