@hh.ru/magritte-ui-chips-input 5.0.11 → 6.0.1
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/ChipsInput.d.ts +2 -1
- package/ChipsInput.js +25 -1
- package/ChipsInput.js.map +1 -1
- package/UncontrolledChipsInput.d.ts +2 -1
- package/UncontrolledChipsInput.js.map +1 -1
- package/index.mock.d.ts +2 -1
- package/index.mock.js +6 -3
- package/index.mock.js.map +1 -1
- package/package.json +6 -6
package/ChipsInput.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ForwardedRef, ReactElement } from 'react';
|
|
2
|
+
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
2
3
|
import { ChipsInputProps } from '@hh.ru/magritte-ui-chips-input/types';
|
|
3
|
-
declare const ChipsInput: (<DataType>(props: ChipsInputProps<DataType> & {
|
|
4
|
+
declare const ChipsInput: (<DataType extends StaticDataFetcherItem>(props: ChipsInputProps<DataType> & {
|
|
4
5
|
ref?: ForwardedRef<HTMLInputElement>;
|
|
5
6
|
}) => ReactElement | null) & {
|
|
6
7
|
displayName: string;
|
package/ChipsInput.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef, useRef, useState } from 'react';
|
|
2
|
+
import { forwardRef, useRef, useState, useEffect } from 'react';
|
|
3
3
|
import { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';
|
|
4
4
|
import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
|
|
5
5
|
import { ChipsTrigger } from '@hh.ru/magritte-ui-chips-trigger';
|
|
@@ -7,6 +7,18 @@ import { Input } from '@hh.ru/magritte-ui-input';
|
|
|
7
7
|
import { Select } from '@hh.ru/magritte-ui-select';
|
|
8
8
|
import { Suggest } from '@hh.ru/magritte-ui-suggest';
|
|
9
9
|
|
|
10
|
+
function areValuesEqual(chips, selectValues) {
|
|
11
|
+
const filteredChipsSet = new Set();
|
|
12
|
+
chips.forEach((item) => {
|
|
13
|
+
if (!item.userInput) {
|
|
14
|
+
filteredChipsSet.add(item.value);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
if (filteredChipsSet.size !== selectValues.length) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return selectValues.every(({ value }) => filteredChipsSet.has(value));
|
|
21
|
+
}
|
|
10
22
|
const getUniqueChips = (selectState, chipsFromState) => {
|
|
11
23
|
const chipsFromUserInput = chipsFromState.filter(({ userInput }) => !!userInput);
|
|
12
24
|
// добавить значения селекта (преобразовать в чипсы их сперва)
|
|
@@ -28,6 +40,17 @@ const ChipsInputComponent = ({ type, state, onChange: onChangeExternal, triggerP
|
|
|
28
40
|
const optionsCountRef = useRef(0);
|
|
29
41
|
const onChangeSuggestRef = useRef();
|
|
30
42
|
const { isMobile } = useBreakpoint();
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (type === 'suggest') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (areValuesEqual(state.chips, selectStateRef.current)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const newSelectState = getInitialSelectValue(type, state.chips);
|
|
51
|
+
selectStateRef.current = newSelectState;
|
|
52
|
+
setSelectState(newSelectState);
|
|
53
|
+
}, [type, state.chips]);
|
|
31
54
|
if (type === 'suggest') {
|
|
32
55
|
return (jsx(Suggest, { ...suggestProps, onChange: (value, isValueFromList) => {
|
|
33
56
|
if (!isValueFromList) {
|
|
@@ -104,6 +127,7 @@ const ChipsInputComponent = ({ type, state, onChange: onChangeExternal, triggerP
|
|
|
104
127
|
chips: [],
|
|
105
128
|
});
|
|
106
129
|
setSelectState([]);
|
|
130
|
+
selectStateRef.current = [];
|
|
107
131
|
}, onSearchSubmit: (event, _, optionsCount, onCloseBottomSheetWithUpdateValues) => {
|
|
108
132
|
const uniqueChips = getUniqueChips(selectStateRef.current, state.chips);
|
|
109
133
|
// добавляем пользовательский ввод из bs, если нужно
|
package/ChipsInput.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChipsInput.js","sources":["../src/ChipsInput.tsx"],"sourcesContent":["import { forwardRef, useRef, ForwardedRef, ReactElement, useState } from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { ChipsInputProps } from '@hh.ru/magritte-ui-chips-input/types';\nimport { ChipsTrigger } from '@hh.ru/magritte-ui-chips-trigger';\nimport { Input } from '@hh.ru/magritte-ui-input';\nimport { Select } from '@hh.ru/magritte-ui-select';\nimport { Suggest } from '@hh.ru/magritte-ui-suggest';\n\ntype ChipsList<DataType extends StaticDataFetcherItem> = ChipsInputProps<DataType>['state']['chips'];\ntype OnChangeSuggest = ((value: string) => void) | undefined;\n\nconst getUniqueChips = <DataType extends StaticDataFetcherItem>(\n selectState: DataType[],\n chipsFromState: ChipsList<DataType>\n): ChipsList<DataType> => {\n const chipsFromUserInput = chipsFromState.filter(({ userInput }) => !!userInput);\n // добавить значения селекта (преобразовать в чипсы их сперва)\n const chipsFromSelect: ChipsList<DataType> =\n selectState.length > 0 ? selectState.map(({ value, text }) => ({ value, label: text, userInput: false })) : [];\n return [...chipsFromSelect, ...chipsFromUserInput];\n};\n\nconst getInitialSelectValue = <DataType extends StaticDataFetcherItem>(\n type: ChipsInputProps<DataType>['type'],\n chips: ChipsInputProps<DataType>['state']['chips']\n): DataType[] => {\n if (type === 'suggest') {\n return [];\n }\n return chips.map((chip) => ({ value: chip.value, text: chip.label }) as DataType);\n};\n\nconst ChipsInputComponent = <DataType extends StaticDataFetcherItem>(\n { type, state, onChange: onChangeExternal, triggerProps, suggestProps, selectProps }: ChipsInputProps<DataType>,\n ref: ForwardedRef<HTMLInputElement>\n) => {\n const chipsTriggerRef = useRef<HTMLInputElement>(null);\n const chipsTriggerRefCallback = useMultipleRefs(ref, chipsTriggerRef);\n const { allowArbitraryValues } = triggerProps;\n const [selectState, setSelectState] = useState(() => getInitialSelectValue<DataType>(type, state.chips));\n const selectStateRef = useRef<DataType[]>(selectState);\n const optionsCountRef = useRef<number>(0);\n const onChangeSuggestRef = useRef<OnChangeSuggest>();\n const { isMobile } = useBreakpoint();\n\n if (type === 'suggest') {\n return (\n <Suggest\n {...suggestProps}\n onChange={(value, isValueFromList) => {\n if (!isValueFromList) {\n return;\n }\n if (!state.chips.some((chip) => chip.value === value)) {\n onChangeExternal({ value: '', chips: [...state.chips, { value }] });\n if (isMobile) {\n onChangeSuggestRef.current?.('');\n }\n }\n }}\n onBottomSheetOpen={() => chipsTriggerRef.current?.blur()}\n input={{\n component: Input,\n props: {\n value: state.value,\n 'data-qa': 'chips-input-suggest-search',\n },\n }}\n onSearchSubmit={(event, onCloseBottomSheet, optionsCount) => {\n if (!allowArbitraryValues || optionsCount > 0) {\n return;\n }\n const value = (event.target as HTMLInputElement).value;\n if (value) {\n onChangeExternal({ value: '', chips: [...state.chips, { value }] });\n onCloseBottomSheet();\n onChangeSuggestRef.current?.('');\n }\n }}\n renderTrigger={({ props, optionsCount }) => {\n const { onChange, wrapperRef, onFocus, onKeyDown } = props;\n onChangeSuggestRef.current = onChange;\n return (\n <ChipsTrigger\n {...triggerProps}\n // разрешаем добавлять результаты только если в suggest ничего не нашли\n allowArbitraryValues={optionsCount === 0 && allowArbitraryValues}\n state={state}\n ref={chipsTriggerRefCallback}\n wrapperRef={wrapperRef}\n onKeyDown={onKeyDown}\n onFocus={onFocus}\n data-qa={triggerProps['data-qa'] || 'chips-input-suggest-trigger'}\n onChange={(newState) => {\n onChangeExternal(newState);\n onChange?.(newState.value);\n }}\n />\n );\n }}\n />\n );\n }\n\n const { applyChangesButton, clearButton } = selectProps;\n const haveApplyChangesButton = Boolean(applyChangesButton);\n const haveClearButton = Boolean(clearButton);\n return (\n <Select\n {...selectProps}\n searchable\n multiple\n value={selectState}\n onSelectOption={(values) => {\n selectStateRef.current = values;\n }}\n onChange={(newValues) => {\n setSelectState(newValues);\n if (haveApplyChangesButton || (haveClearButton && newValues.length === 0)) {\n // обработаем эти кейсы в onApply/onClear\n return;\n }\n const uniqueChips = getUniqueChips(newValues, state.chips);\n onChangeExternal({\n value: '',\n chips: uniqueChips,\n });\n }}\n onOptionsChange={(options) => {\n optionsCountRef.current = options.length;\n }}\n onApply={({ isMobile, searchValue }) => {\n const uniqueChips = getUniqueChips(selectStateRef.current, state.chips);\n // добавляем пользовательский ввод, если нужно\n // в случае bs - из navbar, в случае drop - из chis-trigger\n const userValue = isMobile ? searchValue : state.value;\n if (allowArbitraryValues && userValue.length > 0 && optionsCountRef.current === 0) {\n uniqueChips.push({ value: userValue });\n }\n onChangeExternal({\n value: '',\n chips: uniqueChips,\n });\n // актуализируем состояние селекта\n setSelectState(selectStateRef.current);\n }}\n onClear={() => {\n onChangeExternal({\n value: '',\n chips: [],\n });\n setSelectState([]);\n }}\n onSearchSubmit={(event, _, optionsCount, onCloseBottomSheetWithUpdateValues) => {\n const uniqueChips = getUniqueChips(selectStateRef.current, state.chips);\n // добавляем пользовательский ввод из bs, если нужно\n const userValue = (event.target as HTMLInputElement).value;\n if (allowArbitraryValues && userValue.length > 0 && optionsCount === 0) {\n uniqueChips.push({ value: userValue, userInput: true });\n }\n onChangeExternal({\n value: '',\n chips: uniqueChips,\n });\n setSelectState(selectStateRef.current);\n onCloseBottomSheetWithUpdateValues();\n }}\n triggerProps={{ size: 'large' }}\n renderTrigger={({ ref, setSearchValue, onKeyDown, onBlur, onFocus, optionsCount }) => {\n optionsCountRef.current = optionsCount;\n return (\n <ChipsTrigger\n {...triggerProps}\n allowArbitraryValues={optionsCount === 0 && allowArbitraryValues}\n state={state}\n ref={chipsTriggerRefCallback}\n wrapperRef={ref}\n onKeyDown={onKeyDown}\n onBlur={onBlur}\n onFocus={onFocus}\n data-qa={triggerProps['data-qa'] || 'chips-input-select-trigger'}\n onChange={(newState) => {\n const { event } = newState;\n setSearchValue(newState.value);\n\n // если нажали `enter` в инпуте на desktop\n if (event?.type === 'add' && event.modifier === 'enter') {\n const uniqueChips = getUniqueChips(selectStateRef.current, newState.chips);\n onChangeExternal({\n value: '',\n chips: uniqueChips,\n });\n setSelectState(selectStateRef.current);\n return;\n }\n\n onChangeExternal(newState);\n // если обновился только input, то ререндрить select не нужно\n if (event?.type === 'change' && event.modifier === 'keyboard') {\n return;\n }\n\n // осталось обработать только remove\n const deletedChip = event?.element?.value as string;\n const newSelectState = selectStateRef.current.filter((item) => item.value !== deletedChip);\n setSelectState(newSelectState);\n selectStateRef.current = newSelectState;\n }}\n />\n );\n }}\n />\n );\n};\n\nconst ChipsInput = forwardRef(ChipsInputComponent) as (<DataType>(\n props: ChipsInputProps<DataType> & { ref?: ForwardedRef<HTMLInputElement> }\n) => ReactElement | null) & { displayName: string };\n\nChipsInput.displayName = 'ChipsInput';\n\nexport { ChipsInput };\n"],"names":["_jsx"],"mappings":";;;;;;;;;AAcA,MAAM,cAAc,GAAG,CACnB,WAAuB,EACvB,cAAmC,KACd;AACrB,IAAA,MAAM,kBAAkB,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;;AAEjF,IAAA,MAAM,eAAe,GACjB,WAAW,CAAC,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC;AACnH,IAAA,OAAO,CAAC,GAAG,eAAe,EAAE,GAAG,kBAAkB,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAC1B,IAAuC,EACvC,KAAkD,KACtC;AACZ,IA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yBAAA,CAAC,CAAC;AACH,wBAAA,cAAc,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;wBACvC,OAAO;qBACV;oBAED,gBAAgB,CAAC,QAAQ,CAAC,CAAC;;AAE3B,oBAAA,IAAI,KAAK,EAAE,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,KAAK,UAAU,EAAE;wBAC3D,OAAO;qBACV;;AAGD,oBAAA,MAAM,WAAW,GAAG,KAAK,EAAE,OAAO,EAAE,KAAe,CAAC;AACpD,oBAAA,MAAM,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,KAAK,WAAW,CAAC,CAAC;oBAC3F,cAAc,CAAC,cAAc,CAAC,CAAC;AAC/B,oBAAA,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC;iBAC3C,EAAA,CACH,EACJ;SACL,EAAA,CACH,EACJ;AACN,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,UAAU,CAAC,mBAAmB,EAEG;AAEpD,UAAU,CAAC,WAAW,GAAG,YAAY;;;;"}
|
|
1
|
+
{"version":3,"file":"ChipsInput.js","sources":["../src/ChipsInput.tsx"],"sourcesContent":["import { forwardRef, useRef, ForwardedRef, ReactElement, useState, useEffect } from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { ChipsInputProps } from '@hh.ru/magritte-ui-chips-input/types';\nimport { ChipsTrigger } from '@hh.ru/magritte-ui-chips-trigger';\nimport { Input } from '@hh.ru/magritte-ui-input';\nimport { Select } from '@hh.ru/magritte-ui-select';\nimport { Suggest } from '@hh.ru/magritte-ui-suggest';\n\ntype ChipsList<DataType extends StaticDataFetcherItem> = ChipsInputProps<DataType>['state']['chips'];\ntype OnChangeSuggest = ((value: string) => void) | undefined;\n\nfunction areValuesEqual<DataType extends StaticDataFetcherItem>(\n chips: ChipsInputProps<DataType>['state']['chips'],\n selectValues: DataType[]\n): boolean {\n const filteredChipsSet = new Set<string>();\n chips.forEach((item) => {\n if (!item.userInput) {\n filteredChipsSet.add(item.value);\n }\n });\n if (filteredChipsSet.size !== selectValues.length) {\n return false;\n }\n return selectValues.every(({ value }) => filteredChipsSet.has(value));\n}\n\nconst getUniqueChips = <DataType extends StaticDataFetcherItem>(\n selectState: DataType[],\n chipsFromState: ChipsList<DataType>\n): ChipsList<DataType> => {\n const chipsFromUserInput = chipsFromState.filter(({ userInput }) => !!userInput);\n // добавить значения селекта (преобразовать в чипсы их сперва)\n const chipsFromSelect: ChipsList<DataType> =\n selectState.length > 0 ? selectState.map(({ value, text }) => ({ value, label: text, userInput: false })) : [];\n return [...chipsFromSelect, ...chipsFromUserInput];\n};\n\nconst getInitialSelectValue = <DataType extends StaticDataFetcherItem>(\n type: ChipsInputProps<DataType>['type'],\n chips: ChipsInputProps<DataType>['state']['chips']\n): DataType[] => {\n if (type === 'suggest') {\n return [];\n }\n return chips.map((chip) => ({ value: chip.value, text: chip.label }) as DataType);\n};\n\nconst ChipsInputComponent = <DataType extends StaticDataFetcherItem>(\n { type, state, onChange: onChangeExternal, triggerProps, suggestProps, selectProps }: ChipsInputProps<DataType>,\n ref: ForwardedRef<HTMLInputElement>\n) => {\n const chipsTriggerRef = useRef<HTMLInputElement>(null);\n const chipsTriggerRefCallback = useMultipleRefs(ref, chipsTriggerRef);\n const { allowArbitraryValues } = triggerProps;\n const [selectState, setSelectState] = useState(() => getInitialSelectValue<DataType>(type, state.chips));\n const selectStateRef = useRef<DataType[]>(selectState);\n const optionsCountRef = useRef<number>(0);\n const onChangeSuggestRef = useRef<OnChangeSuggest>();\n const { isMobile } = useBreakpoint();\n\n useEffect(() => {\n if (type === 'suggest') {\n return;\n }\n if (areValuesEqual(state.chips, selectStateRef.current)) {\n return;\n }\n const newSelectState = getInitialSelectValue<DataType>(type, state.chips);\n selectStateRef.current = newSelectState;\n setSelectState(newSelectState);\n }, [type, state.chips]);\n\n if (type === 'suggest') {\n return (\n <Suggest\n {...suggestProps}\n onChange={(value, isValueFromList) => {\n if (!isValueFromList) {\n return;\n }\n if (!state.chips.some((chip) => chip.value === value)) {\n onChangeExternal({ value: '', chips: [...state.chips, { value }] });\n if (isMobile) {\n onChangeSuggestRef.current?.('');\n }\n }\n }}\n onBottomSheetOpen={() => chipsTriggerRef.current?.blur()}\n input={{\n component: Input,\n props: {\n value: state.value,\n 'data-qa': 'chips-input-suggest-search',\n },\n }}\n onSearchSubmit={(event, onCloseBottomSheet, optionsCount) => {\n if (!allowArbitraryValues || optionsCount > 0) {\n return;\n }\n const value = (event.target as HTMLInputElement).value;\n if (value) {\n onChangeExternal({ value: '', chips: [...state.chips, { value }] });\n onCloseBottomSheet();\n onChangeSuggestRef.current?.('');\n }\n }}\n renderTrigger={({ props, optionsCount }) => {\n const { onChange, wrapperRef, onFocus, onKeyDown } = props;\n onChangeSuggestRef.current = onChange;\n return (\n <ChipsTrigger\n {...triggerProps}\n // разрешаем добавлять результаты только если в suggest ничего не нашли\n allowArbitraryValues={optionsCount === 0 && allowArbitraryValues}\n state={state}\n ref={chipsTriggerRefCallback}\n wrapperRef={wrapperRef}\n onKeyDown={onKeyDown}\n onFocus={onFocus}\n data-qa={triggerProps['data-qa'] || 'chips-input-suggest-trigger'}\n onChange={(newState) => {\n onChangeExternal(newState);\n onChange?.(newState.value);\n }}\n />\n );\n }}\n />\n );\n }\n\n const { applyChangesButton, clearButton } = selectProps;\n const haveApplyChangesButton = Boolean(applyChangesButton);\n const haveClearButton = Boolean(clearButton);\n return (\n <Select\n {...selectProps}\n searchable\n multiple\n value={selectState}\n onSelectOption={(values) => {\n selectStateRef.current = values;\n }}\n onChange={(newValues) => {\n setSelectState(newValues);\n if (haveApplyChangesButton || (haveClearButton && newValues.length === 0)) {\n // обработаем эти кейсы в onApply/onClear\n return;\n }\n const uniqueChips = getUniqueChips(newValues, state.chips);\n onChangeExternal({\n value: '',\n chips: uniqueChips,\n });\n }}\n onOptionsChange={(options) => {\n optionsCountRef.current = options.length;\n }}\n onApply={({ isMobile, searchValue }) => {\n const uniqueChips = getUniqueChips(selectStateRef.current, state.chips);\n // добавляем пользовательский ввод, если нужно\n // в случае bs - из navbar, в случае drop - из chis-trigger\n const userValue = isMobile ? searchValue : state.value;\n if (allowArbitraryValues && userValue.length > 0 && optionsCountRef.current === 0) {\n uniqueChips.push({ value: userValue });\n }\n onChangeExternal({\n value: '',\n chips: uniqueChips,\n });\n // актуализируем состояние селекта\n setSelectState(selectStateRef.current);\n }}\n onClear={() => {\n onChangeExternal({\n value: '',\n chips: [],\n });\n setSelectState([]);\n selectStateRef.current = [];\n }}\n onSearchSubmit={(event, _, optionsCount, onCloseBottomSheetWithUpdateValues) => {\n const uniqueChips = getUniqueChips(selectStateRef.current, state.chips);\n // добавляем пользовательский ввод из bs, если нужно\n const userValue = (event.target as HTMLInputElement).value;\n if (allowArbitraryValues && userValue.length > 0 && optionsCount === 0) {\n uniqueChips.push({ value: userValue, userInput: true });\n }\n onChangeExternal({\n value: '',\n chips: uniqueChips,\n });\n setSelectState(selectStateRef.current);\n onCloseBottomSheetWithUpdateValues();\n }}\n triggerProps={{ size: 'large' }}\n renderTrigger={({ ref, setSearchValue, onKeyDown, onBlur, onFocus, optionsCount }) => {\n optionsCountRef.current = optionsCount;\n return (\n <ChipsTrigger\n {...triggerProps}\n allowArbitraryValues={optionsCount === 0 && allowArbitraryValues}\n state={state}\n ref={chipsTriggerRefCallback}\n wrapperRef={ref}\n onKeyDown={onKeyDown}\n onBlur={onBlur}\n onFocus={onFocus}\n data-qa={triggerProps['data-qa'] || 'chips-input-select-trigger'}\n onChange={(newState) => {\n const { event } = newState;\n setSearchValue(newState.value);\n\n // если нажали `enter` в инпуте на desktop\n if (event?.type === 'add' && event.modifier === 'enter') {\n const uniqueChips = getUniqueChips(selectStateRef.current, newState.chips);\n onChangeExternal({\n value: '',\n chips: uniqueChips,\n });\n setSelectState(selectStateRef.current);\n return;\n }\n\n onChangeExternal(newState);\n // если обновился только input, то ререндрить select не нужно\n if (event?.type === 'change' && event.modifier === 'keyboard') {\n return;\n }\n\n // осталось обработать только remove\n const deletedChip = event?.element?.value as string;\n const newSelectState = selectStateRef.current.filter((item) => item.value !== deletedChip);\n setSelectState(newSelectState);\n selectStateRef.current = newSelectState;\n }}\n />\n );\n }}\n />\n );\n};\n\nconst ChipsInput = forwardRef(ChipsInputComponent) as (<DataType extends StaticDataFetcherItem>(\n props: ChipsInputProps<DataType> & { ref?: ForwardedRef<HTMLInputElement> }\n) => ReactElement | null) & { displayName: string };\n\nChipsInput.displayName = 'ChipsInput';\n\nexport { ChipsInput };\n"],"names":["_jsx"],"mappings":";;;;;;;;;AAcA,SAAS,cAAc,CACnB,KAAkD,EAClD,YAAwB,EAAA;AAExB,IAAA,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;AAC3C,IAAA,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;AACnB,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;AACjB,YAAA,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpC;AACL,KAAC,CAAC,CAAC;IACH,IAAI,gBAAgB,CAAC,IAAI,KAAK,YAAY,CAAC,MAAM,EAAE;AAC/C,QAAA,OAAO,KAAK,CAAC;KAChB;AACD,IAAA,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,cAAc,GAAG,CACnB,WAAuB,EACvB,cAAmC,KACd;AACrB,IAAA,MAAM,kBAAkB,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;;AAEjF,IAAA,MAAM,eAA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KAAK,KAAK,WAAW,CAAC,CAAC;oBAC3F,cAAc,CAAC,cAAc,CAAC,CAAC;AAC/B,oBAAA,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC;iBAC3C,EAAA,CACH,EACJ;SACL,EAAA,CACH,EACJ;AACN,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,UAAU,CAAC,mBAAmB,EAEG;AAEpD,UAAU,CAAC,WAAW,GAAG,YAAY;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ForwardedRef, ReactElement } from 'react';
|
|
2
|
+
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
2
3
|
import { UncontrolledChipsInputProps } from '@hh.ru/magritte-ui-chips-input/types';
|
|
3
|
-
declare const UncontrolledChipsInput: (<DataType>(props: UncontrolledChipsInputProps<DataType> & {
|
|
4
|
+
declare const UncontrolledChipsInput: (<DataType extends StaticDataFetcherItem>(props: UncontrolledChipsInputProps<DataType> & {
|
|
4
5
|
ref?: ForwardedRef<HTMLInputElement>;
|
|
5
6
|
}) => ReactElement | null) & {
|
|
6
7
|
displayName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UncontrolledChipsInput.js","sources":["../src/UncontrolledChipsInput.tsx"],"sourcesContent":["import { forwardRef, useState, ForwardedRef, ReactElement } from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { ChipsInput } from '@hh.ru/magritte-ui-chips-input/ChipsInput';\nimport { UncontrolledChipsInputProps } from '@hh.ru/magritte-ui-chips-input/types';\nimport { ChipsTriggerState } from '@hh.ru/magritte-ui-chips-trigger/types';\n\nconst DEFAULT_STATE = {\n value: '',\n chips: [],\n};\n\nconst UncontrolledChipsInputComponent = <DataType extends StaticDataFetcherItem>(\n { state: defaultState = DEFAULT_STATE, onChange, name, ...restProps }: UncontrolledChipsInputProps<DataType>,\n ref: ForwardedRef<HTMLInputElement>\n) => {\n const [state, setState] = useState<ChipsTriggerState>({ ...defaultState });\n return (\n <>\n <ChipsInput\n {...restProps}\n state={state}\n onChange={(newState) => {\n setState(newState);\n onChange?.(newState);\n }}\n ref={ref}\n />\n {state.chips.map((chip) => (\n <input type=\"hidden\" name={name} value={chip.value} key={chip.value} />\n ))}\n </>\n );\n};\n\nconst UncontrolledChipsInput = forwardRef(UncontrolledChipsInputComponent) as (<DataType>(\n props: UncontrolledChipsInputProps<DataType> & { ref?: ForwardedRef<HTMLInputElement> }\n) => ReactElement | null) & { displayName: string };\n\nUncontrolledChipsInput.displayName = 'UncontrolledChipsInput';\n\nexport { UncontrolledChipsInput };\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;AAOA,MAAM,aAAa,GAAG;AAClB,IAAA,KAAK,EAAE,EAAE;AACT,IAAA,KAAK,EAAE,EAAE;CACZ,CAAC;AAEF,MAAM,+BAA+B,GAAG,CACpC,EAAE,KAAK,EAAE,YAAY,GAAG,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,SAAS,EAAyC,EAC5G,GAAmC,KACnC;AACA,IAAA,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAoB,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC;AAC3E,IAAA,QACIA,IACI,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CAAAC,GAAA,CAAC,UAAU,EAAA,EAAA,GACH,SAAS,EACb,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,CAAC,QAAQ,KAAI;oBACnB,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACnB,oBAAA,QAAQ,GAAG,QAAQ,CAAC,CAAC;AACzB,iBAAC,EACD,GAAG,EAAE,GAAG,EACV,CAAA,EACD,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,MAClBA,GAAO,CAAA,OAAA,EAAA,EAAA,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAO,EAAA,IAAI,CAAC,KAAK,CAAI,CAC1E,CAAC,CAAA,EAAA,CACH,EACL;AACN,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,UAAU,CAAC,+BAA+B,EAErB;AAEpD,sBAAsB,CAAC,WAAW,GAAG,wBAAwB;;;;"}
|
|
1
|
+
{"version":3,"file":"UncontrolledChipsInput.js","sources":["../src/UncontrolledChipsInput.tsx"],"sourcesContent":["import { forwardRef, useState, ForwardedRef, ReactElement } from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { ChipsInput } from '@hh.ru/magritte-ui-chips-input/ChipsInput';\nimport { UncontrolledChipsInputProps } from '@hh.ru/magritte-ui-chips-input/types';\nimport { ChipsTriggerState } from '@hh.ru/magritte-ui-chips-trigger/types';\n\nconst DEFAULT_STATE = {\n value: '',\n chips: [],\n};\n\nconst UncontrolledChipsInputComponent = <DataType extends StaticDataFetcherItem>(\n { state: defaultState = DEFAULT_STATE, onChange, name, ...restProps }: UncontrolledChipsInputProps<DataType>,\n ref: ForwardedRef<HTMLInputElement>\n) => {\n const [state, setState] = useState<ChipsTriggerState>({ ...defaultState });\n return (\n <>\n <ChipsInput\n {...restProps}\n state={state}\n onChange={(newState) => {\n setState(newState);\n onChange?.(newState);\n }}\n ref={ref}\n />\n {state.chips.map((chip) => (\n <input type=\"hidden\" name={name} value={chip.value} key={chip.value} />\n ))}\n </>\n );\n};\n\nconst UncontrolledChipsInput = forwardRef(UncontrolledChipsInputComponent) as (<DataType extends StaticDataFetcherItem>(\n props: UncontrolledChipsInputProps<DataType> & { ref?: ForwardedRef<HTMLInputElement> }\n) => ReactElement | null) & { displayName: string };\n\nUncontrolledChipsInput.displayName = 'UncontrolledChipsInput';\n\nexport { UncontrolledChipsInput };\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;AAOA,MAAM,aAAa,GAAG;AAClB,IAAA,KAAK,EAAE,EAAE;AACT,IAAA,KAAK,EAAE,EAAE;CACZ,CAAC;AAEF,MAAM,+BAA+B,GAAG,CACpC,EAAE,KAAK,EAAE,YAAY,GAAG,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,SAAS,EAAyC,EAC5G,GAAmC,KACnC;AACA,IAAA,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAoB,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC;AAC3E,IAAA,QACIA,IACI,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CAAAC,GAAA,CAAC,UAAU,EAAA,EAAA,GACH,SAAS,EACb,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,CAAC,QAAQ,KAAI;oBACnB,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACnB,oBAAA,QAAQ,GAAG,QAAQ,CAAC,CAAC;AACzB,iBAAC,EACD,GAAG,EAAE,GAAG,EACV,CAAA,EACD,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,MAClBA,GAAO,CAAA,OAAA,EAAA,EAAA,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAO,EAAA,IAAI,CAAC,KAAK,CAAI,CAC1E,CAAC,CAAA,EAAA,CACH,EACL;AACN,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,UAAU,CAAC,+BAA+B,EAErB;AAEpD,sBAAsB,CAAC,WAAW,GAAG,wBAAwB;;;;"}
|
package/index.mock.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import { ForwardRefExoticComponent } from 'react';
|
|
|
2
2
|
export type * from '@hh.ru/magritte-ui-chips-input/types';
|
|
3
3
|
declare const ThemeProvider: any;
|
|
4
4
|
export { ThemeProvider };
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const ChipsInput: ForwardRefExoticComponent<Record<string, unknown>>;
|
|
6
|
+
export declare const UncontrolledChipsInput: ForwardRefExoticComponent<Record<string, unknown>>;
|
package/index.mock.js
CHANGED
|
@@ -2,9 +2,12 @@ import { mockComponent } from '@hh.ru/magritte-ui-mock-component';
|
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
4
4
|
const { ThemeProvider } = jest.requireActual('@hh.ru/magritte-ui-theme-provider/index');
|
|
5
|
-
const
|
|
6
|
-
withChildren:
|
|
5
|
+
const ChipsInput = mockComponent('ChipsInput', undefined, {
|
|
6
|
+
withChildren: true,
|
|
7
|
+
});
|
|
8
|
+
const UncontrolledChipsInput = mockComponent('UncontrolledChipsInput', undefined, {
|
|
9
|
+
withChildren: true,
|
|
7
10
|
});
|
|
8
11
|
|
|
9
|
-
export {
|
|
12
|
+
export { ChipsInput, ThemeProvider, UncontrolledChipsInput };
|
|
10
13
|
//# sourceMappingURL=index.mock.js.map
|
package/index.mock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mock.js","sources":["../src/index.mock.ts"],"sourcesContent":["import { ForwardRefExoticComponent } from 'react';\n\nimport { mockComponent } from '@hh.ru/magritte-ui-mock-component';\n\nexport type * from '@hh.ru/magritte-ui-chips-input/types';\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nconst { ThemeProvider } = jest.requireActual('@hh.ru/magritte-ui-theme-provider/index');\n\nexport { ThemeProvider };\n\nexport const
|
|
1
|
+
{"version":3,"file":"index.mock.js","sources":["../src/index.mock.ts"],"sourcesContent":["import { ForwardRefExoticComponent } from 'react';\n\nimport { mockComponent } from '@hh.ru/magritte-ui-mock-component';\n\nexport type * from '@hh.ru/magritte-ui-chips-input/types';\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nconst { ThemeProvider } = jest.requireActual('@hh.ru/magritte-ui-theme-provider/index');\n\nexport { ThemeProvider };\n\nexport const ChipsInput: ForwardRefExoticComponent<Record<string, unknown>> = mockComponent('ChipsInput', undefined, {\n withChildren: true,\n});\n\nexport const UncontrolledChipsInput: ForwardRefExoticComponent<Record<string, unknown>> = mockComponent(\n 'UncontrolledChipsInput',\n undefined,\n {\n withChildren: true,\n }\n);\n"],"names":[],"mappings":";;AAMA;AACM,MAAA,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,yCAAyC,EAAE;MAI3E,UAAU,GAAuD,aAAa,CAAC,YAAY,EAAE,SAAS,EAAE;AACjH,IAAA,YAAY,EAAE,IAAI;AACrB,CAAA,EAAE;MAEU,sBAAsB,GAAuD,aAAa,CACnG,wBAAwB,EACxB,SAAS,EACT;AACI,IAAA,YAAY,EAAE,IAAI;AACrB,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hh.ru/magritte-ui-chips-input",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"sideEffects": [
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"react": ">=18.2.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@hh.ru/magritte-common-data-provider": "1.
|
|
29
|
+
"@hh.ru/magritte-common-data-provider": "1.2.0",
|
|
30
30
|
"@hh.ru/magritte-common-use-multiple-refs": "1.1.5",
|
|
31
31
|
"@hh.ru/magritte-ui-breakpoint": "5.0.0",
|
|
32
|
-
"@hh.ru/magritte-ui-chips-trigger": "3.3.
|
|
32
|
+
"@hh.ru/magritte-ui-chips-trigger": "3.3.14",
|
|
33
33
|
"@hh.ru/magritte-ui-input": "7.1.16",
|
|
34
34
|
"@hh.ru/magritte-ui-mock-component": "1.0.12",
|
|
35
|
-
"@hh.ru/magritte-ui-select": "10.0.
|
|
36
|
-
"@hh.ru/magritte-ui-suggest": "
|
|
35
|
+
"@hh.ru/magritte-ui-select": "10.0.13",
|
|
36
|
+
"@hh.ru/magritte-ui-suggest": "8.0.1",
|
|
37
37
|
"@hh.ru/magritte-ui-theme-provider": "1.1.41"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "45423cebe8915eca05c73df986715979d386f7be"
|
|
40
40
|
}
|