Skip to content

Commit 647df38

Browse files
feat: New InputGroup component
1 parent 7490718 commit 647df38

18 files changed

Lines changed: 288 additions & 0 deletions
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './useInputGroup';
2+
export * from './useInputGroup.props';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { useInputGroupProps } from '@primereact/types/shared/inputgroup';
2+
3+
export const defaultProps: useInputGroupProps = {};

packages/headless/src/inputgroup/useInputGroup.test.ts

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { withHeadless } from '@primereact/core/headless';
2+
import { defaultProps } from './useInputGroup.props';
3+
4+
export const useInputGroup = withHeadless({
5+
name: 'useInputGroup',
6+
defaultProps
7+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createOptionalContext } from '@primereact/core/utils';
2+
import type { InputGroupInstance } from '@primereact/types/shared/inputgroup';
3+
4+
export const [InputGroupProvider, useInputGroupContext] = createOptionalContext<InputGroupInstance>();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { InputGroupProps } from '@primereact/types/shared/inputgroup';
2+
3+
export const defaultProps: InputGroupProps = {
4+
as: 'div'
5+
};

packages/primereact/src/inputgroup/InputGroup.test.ts

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use client';
2+
import { Component } from '@primereact/core/component';
3+
import { useInputGroup } from '@primereact/headless/inputgroup';
4+
import { styles } from '@primereact/styles/inputgroup';
5+
import { mergeProps } from '@primeuix/utils';
6+
import { withComponent } from 'primereact/base';
7+
import * as React from 'react';
8+
import { InputGroupProvider } from './InputGroup.context';
9+
import { defaultProps } from './InputGroup.props';
10+
import { InputGroupAddon } from './addon';
11+
12+
export const InputGroup = withComponent({
13+
name: 'InputGroup',
14+
defaultProps,
15+
styles,
16+
setup(instance) {
17+
const inputgroup = useInputGroup(instance?.inProps);
18+
19+
return inputgroup;
20+
},
21+
render(instance) {
22+
const { id, props, ptmi, cx } = instance;
23+
24+
const rootProps = mergeProps(
25+
{
26+
id,
27+
className: cx('root')
28+
},
29+
ptmi('root')
30+
);
31+
32+
return (
33+
<InputGroupProvider value={instance}>
34+
<Component instance={instance} attrs={rootProps} children={props.children} />
35+
</InputGroupProvider>
36+
);
37+
},
38+
components: {
39+
Addon: InputGroupAddon
40+
}
41+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { InputGroupAddonProps } from '@primereact/types/shared/inputgroup';
2+
3+
export const defaultAddonProps: InputGroupAddonProps = {
4+
as: 'div'
5+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use client';
2+
import { Component } from '@primereact/core/component';
3+
import { mergeProps } from '@primeuix/utils';
4+
import { withComponent } from 'primereact/base';
5+
import * as React from 'react';
6+
import { useInputGroupContext } from '../InputGroup.context';
7+
import { defaultAddonProps } from './InputGroupAddon.props';
8+
9+
export const InputGroupAddon = withComponent({
10+
name: 'InputGroupAddon',
11+
defaultProps: defaultAddonProps,
12+
setup() {
13+
const inputgroup = useInputGroupContext();
14+
15+
return { inputgroup };
16+
},
17+
render(instance) {
18+
const { props, ptmi, inputgroup } = instance;
19+
20+
const rootProps = mergeProps(
21+
{
22+
className: inputgroup?.cx('addon')
23+
},
24+
inputgroup?.ptm('addon'),
25+
ptmi('root')
26+
);
27+
28+
return <Component instance={instance} attrs={rootProps} children={props.children} />;
29+
}
30+
});

0 commit comments

Comments
 (0)