Skip to content

Commit a08cc51

Browse files
committed
feat: added new prop for focusoutline color change
1 parent 11dd898 commit a08cc51

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

src/components/primitives/Input/Input.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const Input = (
3636
callback();
3737
};
3838

39+
/**Converting into Hash Color Code */
40+
//@ts-ignore
41+
props.focusOutlineColor = useToken('colors', props.focusOutlineColor);
42+
3943
const _ref = React.useRef(null);
4044
const { isHovered } = useHover({}, _ref);
4145

@@ -68,6 +72,7 @@ const Input = (
6872
wrapperRef,
6973
_stack,
7074
_input,
75+
7176
...resolvedProps
7277
} = usePropsResolution(
7378
'Input',

src/components/primitives/Input/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
VariantType,
77
} from '../../types';
88
import type { InterfaceBoxProps } from '../Box';
9-
import type { ResponsiveValue } from '../../../components/types';
9+
import type { ResponsiveValue, ColorType } from '../../../components/types';
1010
import type { ISizes } from '../../../theme/base/sizes';
1111
import type { CustomProps } from '../../types';
1212
import type { IStackProps } from '../Stack/Stack';
@@ -106,6 +106,8 @@ export interface InterfaceInputProps
106106
* Props to be passed to the Stack used inside.
107107
*/
108108
_stack?: Partial<IStackProps>;
109+
/** This prop allow you to change outlineColor when input is in focused state*/
110+
focusOutlineColor?: ColorType;
109111
}
110112

111113
export interface IInputGroupProps extends InterfaceBoxProps<IInputGroupProps> {

src/theme/components/input.ts

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
import { transparentize, mode } from '../tools';
2-
1+
import { transparentize } from '../tools';
32
const baseStyle = (props: any) => {
43
const { primary } = props.theme.colors;
5-
const focusRing = mode(
6-
{
7-
outlineWidth: '1px',
8-
outlineColor: `${primary[600]}`,
9-
outlineStyle: 'solid',
10-
},
11-
{
12-
outlineWidth: '1px',
13-
outlineColor: `${primary[500]}`,
14-
outlineStyle: 'solid',
15-
}
16-
)(props);
4+
175
return {
186
fontFamily: 'body',
197
py: '2',
@@ -49,6 +37,13 @@ const baseStyle = (props: any) => {
4937
},
5038
_focus: {
5139
borderColor: 'primary.600',
40+
_stack: {
41+
style: {
42+
outlineWidth: '1px',
43+
outlineColor: `${props.focusOutlineColor || primary[600]}`,
44+
outlineStyle: 'solid',
45+
},
46+
},
5247
},
5348
_invalid: {
5449
borderColor: 'error.600',
@@ -70,9 +65,6 @@ const baseStyle = (props: any) => {
7065
alignItems: 'center',
7166
// justifyContent: 'space-between',
7267
overflow: 'hidden',
73-
_focus: {
74-
style: { ...focusRing },
75-
},
7668
},
7769
},
7870
_dark: {
@@ -84,6 +76,13 @@ const baseStyle = (props: any) => {
8476
},
8577
_focus: {
8678
borderColor: 'primary.500',
79+
_stack: {
80+
style: {
81+
outlineWidth: '1px',
82+
outlineColor: `${props.focusOutlineColor || primary[500]}`,
83+
outlineStyle: 'solid',
84+
},
85+
},
8786
},
8887
_invalid: {
8988
borderColor: 'error.500',
@@ -105,9 +104,6 @@ const baseStyle = (props: any) => {
105104
alignItems: 'center',
106105
// justifyContent: 'space-between',
107106
overflow: 'hidden',
108-
_focus: {
109-
style: { ...focusRing },
110-
},
111107
},
112108
},
113109
};
@@ -185,16 +181,30 @@ function unstyledStyle() {
185181
},
186182
};
187183
}
188-
function underlinedStyle() {
184+
function underlinedStyle(props: Record<string, any>) {
185+
const { primary } = props.theme.colors;
186+
189187
return {
190188
borderWidth: '0',
191189
pl: '0',
192190
borderBottomWidth: '1',
193-
_stack: {
194-
_focus: {
195-
style: {
196-
outlineWidth: '0',
197-
boxShadow: '0 1px 0 0 #0891B2',
191+
_light: {
192+
_stack: {
193+
_focus: {
194+
style: {
195+
outlineWidth: '0',
196+
boxShadow: `0 1px 0 0 ${props.focusOutlineColor || primary[600]}`,
197+
},
198+
},
199+
},
200+
},
201+
_dark: {
202+
_stack: {
203+
_focus: {
204+
style: {
205+
outlineWidth: '0',
206+
boxShadow: `0 1px 0 0 ${props.focusOutlineColor || primary[500]}`,
207+
},
198208
},
199209
},
200210
},

0 commit comments

Comments
 (0)