Skip to content

Commit

Permalink
Merge pull request #1318 from nsbno/search-input-width
Browse files Browse the repository at this point in the history
Direct width-related props to InputGroup.
  • Loading branch information
mcklien authored Nov 21, 2024
2 parents 8897201 + 40b8191 commit 12d1c2b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-pots-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vygruppen/spor-react": minor
---

SearchInput: Added support for width-related props
24 changes: 22 additions & 2 deletions packages/spor-react/src/input/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Input as ChakraInput,
InputProps as ChakraInputProps,
IconButton,
LayoutProps,
forwardRef,
useFormControlContext,
} from "@chakra-ui/react";
Expand Down Expand Up @@ -33,15 +34,18 @@ export const SearchInput = forwardRef<SearchInputProps, "input">(
const formControlProps = useFormControlContext();
const autoGeneratedId = useId();
const inputId = props.id ?? formControlProps?.id ?? autoGeneratedId;

const { outerProps, innerProps } = getOuterProps(props);

return (
<InputGroup position="relative">
<InputGroup position="relative" {...outerProps}>
<InputLeftElement>
<SearchOutline24Icon />
</InputLeftElement>
<ChakraInput
paddingLeft={7}
paddingRight={7}
{...props}
{...innerProps}
id={inputId}
type="search"
css={{
Expand Down Expand Up @@ -74,6 +78,22 @@ export const SearchInput = forwardRef<SearchInputProps, "input">(
},
);

const getOuterProps = (props: Record<string, any>) => {
const layoutKeys = new Set(["w, width, maxW, minW, maxWidth, minWidth"]); // add more keys here if neccessary
const outerProps: LayoutProps = {};
const innerProps: Record<string, any> = {};

for (const key in props) {
if (layoutKeys.has(key)) {
(outerProps as any)[key] = props[key];
} else {
(innerProps as any)[key] = props[key];
}
}

return { outerProps, innerProps };
};

const texts = createTexts({
label: {
nb: "Søk",
Expand Down

0 comments on commit 12d1c2b

Please sign in to comment.