Skip to content

Commit 796ec83

Browse files
feat: Add IconField
1 parent 7490718 commit 796ec83

18 files changed

Lines changed: 291 additions & 0 deletions

File tree

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

packages/headless/src/iconfield/useIconField.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 './useIconField.props';
3+
4+
export const useIconField = withHeadless({
5+
name: 'useIconField',
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 { IconFieldInstance } from '@primereact/types/shared/iconfield';
3+
4+
export const [IconFieldProvider, useIconFieldContext] = createOptionalContext<IconFieldInstance>();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { IconFieldProps } from '@primereact/types/shared/iconfield';
2+
3+
export const defaultProps: IconFieldProps = {
4+
as: 'div'
5+
};

packages/primereact/src/iconfield/IconField.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 { useIconField } from '@primereact/headless/iconfield';
4+
import { styles } from '@primereact/styles/iconfield';
5+
import { mergeProps } from '@primeuix/utils';
6+
import { withComponent } from 'primereact/base';
7+
import * as React from 'react';
8+
import { IconFieldProvider } from './IconField.context';
9+
import { defaultProps } from './IconField.props';
10+
import { InputIcon } from './icon';
11+
12+
export const IconField = withComponent({
13+
name: 'IconField',
14+
defaultProps,
15+
styles,
16+
setup(instance) {
17+
const inputicon = useIconField(instance?.inProps);
18+
19+
return inputicon;
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+
<IconFieldProvider value={instance}>
34+
<Component instance={instance} attrs={rootProps} children={props.children} />
35+
</IconFieldProvider>
36+
);
37+
},
38+
components: {
39+
Icon: InputIcon
40+
}
41+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { InputIconProps } from '@primereact/types/shared/iconfield';
2+
3+
export const defaultIconProps: InputIconProps = {
4+
as: 'div'
5+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 { useIconFieldContext } from '../IconField.context';
7+
import { defaultIconProps } from './InputIcon.props';
8+
9+
export const InputIcon = withComponent({
10+
name: 'InputIcon',
11+
defaultProps: defaultIconProps,
12+
setup() {
13+
const iconfield = useIconFieldContext();
14+
15+
return { iconfield };
16+
},
17+
render(instance) {
18+
const { props, ptmi, iconfield } = instance;
19+
20+
const rootProps = mergeProps(
21+
{
22+
className: iconfield?.cx('icon')
23+
},
24+
ptmi('root')
25+
);
26+
27+
return <Component instance={instance} attrs={rootProps} children={props.children} />;
28+
}
29+
});

0 commit comments

Comments
 (0)