Skip to content

Commit

Permalink
Merge pull request #1195 from kadena-community/refactor/rename-input-…
Browse files Browse the repository at this point in the history
…wrapper

Refactor/rename input wrapper
  • Loading branch information
ferreroltd authored Nov 9, 2023
2 parents d58bce7 + df48185 commit cbdc36b
Show file tree
Hide file tree
Showing 31 changed files with 157 additions and 130 deletions.
6 changes: 6 additions & 0 deletions .changeset/new-pianos-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@kadena/react-ui': minor
---

Refactor InputFieldWrapper for the new FormFieldWrapper component with stacked
items
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import routes from '@/constants/routes';
import { Text } from '@components/text';
import { Button, Grid, Input, InputWrapper, Select } from '@kadena/react-ui';
import {
Button,
FormFieldWrapper,
Grid,
Input,
Select,
} from '@kadena/react-ui';
import { useRouter } from 'next/router';
import type { FC } from 'react';
import React, { useState } from 'react';
Expand Down Expand Up @@ -166,7 +172,7 @@ const Header: FC<IHeaderProps> = (props) => {

<Grid.Root columns={gridColumns}>
<Grid.Item>
<InputWrapper htmlFor="search-type" label="Search Type">
<FormFieldWrapper htmlFor="search-type" label="Search Type">
<Select
ariaLabel="search-type"
id="search-type"
Expand All @@ -179,11 +185,11 @@ const Header: FC<IHeaderProps> = (props) => {
<option value="block">Block</option>
<option value="gasEstimation">Gas Estimation</option>
</Select>
</InputWrapper>
</FormFieldWrapper>
</Grid.Item>

<Grid.Item>
<InputWrapper
<FormFieldWrapper
htmlFor="search-field"
label={searchTypeLabels[searchType]}
>
Expand All @@ -194,13 +200,13 @@ const Header: FC<IHeaderProps> = (props) => {
onChange={handleSearchFieldChange}
onKeyDown={handleKeyPress}
/>
</InputWrapper>
</FormFieldWrapper>
</Grid.Item>

{(searchType.startsWith('account') ||
searchType.startsWith('gas')) && (
<Grid.Item>
<InputWrapper
<FormFieldWrapper
htmlFor="second-search-field"
label={secondSearchTypeLabels[searchType]}
>
Expand All @@ -211,13 +217,13 @@ const Header: FC<IHeaderProps> = (props) => {
onChange={(event) => setSecondSearchField(event.target.value)}
onKeyDown={handleKeyPress}
/>
</InputWrapper>
</FormFieldWrapper>
</Grid.Item>
)}

{searchType.startsWith('gas') && (
<Grid.Item>
<InputWrapper
<FormFieldWrapper
htmlFor="third-search-field"
label={thirdSeachTypeLabels[searchType]}
>
Expand All @@ -228,7 +234,7 @@ const Header: FC<IHeaderProps> = (props) => {
onChange={(event) => setThirdSearchField(event.target.value)}
onKeyDown={handleKeyPress}
/>
</InputWrapper>
</FormFieldWrapper>
</Grid.Item>
)}
<Grid.Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useWalletConnectClient } from '@/context/connect-wallet-context';
import { useDidUpdateEffect } from '@/hooks';
import { getAccounts } from '@/utils/wallet';
import type {
IFormFieldWrapperProps,
IInputProps,
IInputWrapperProps,
ISelectProps,
} from '@kadena/react-ui';
import {
FormFieldWrapper,
IconButton,
Input,
InputWrapper,
Select,
maskValue,
} from '@kadena/react-ui';
Expand All @@ -21,7 +21,7 @@ import * as z from 'zod';
import { accountInputWrapperStyle } from './styles.css';

interface IAccountNameFieldProps
extends Partial<Omit<IInputWrapperProps, 'children'>> {
extends Partial<Omit<IFormFieldWrapperProps, 'children'>> {
inputProps: Partial<
Pick<
IInputProps,
Expand Down Expand Up @@ -98,15 +98,15 @@ export const AccountNameField: FC<IAccountNameFieldProps> = ({

return (
<div className={accountInputWrapperStyle}>
<InputWrapper
<FormFieldWrapper
label={t('Account')}
htmlFor={elementId}
status={error ? 'negative' : status}
helperText={error?.message ?? helperText}
{...rest}
>
{lookup[mode]}
</InputWrapper>
</FormFieldWrapper>
{accounts?.length && (
<IconButton
icon={mode === 'input' ? 'Close' : 'Edit'}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ChainwebChainId } from '@kadena/chainweb-node-client';
import { CHAINS } from '@kadena/chainweb-node-client';
import type { ISelectProps } from '@kadena/react-ui';
import { InputWrapper, Select } from '@kadena/react-ui';
import { FormFieldWrapper, Select } from '@kadena/react-ui';
import type { FC, FormEventHandler } from 'react';
import React, { useCallback } from 'react';

Expand Down Expand Up @@ -32,7 +32,7 @@ const ChainSelect: FC<
});

return (
<InputWrapper label="Chain ID" htmlFor={ELEMENT_ID}>
<FormFieldWrapper label="Chain ID" htmlFor={ELEMENT_ID}>
<Select
{...rest}
id={ELEMENT_ID}
Expand All @@ -43,7 +43,7 @@ const ChainSelect: FC<
>
{options}
</Select>
</InputWrapper>
</FormFieldWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ISelectProps } from '@kadena/react-ui';
import { InputWrapper, Select } from '@kadena/react-ui';
import { FormFieldWrapper, Select } from '@kadena/react-ui';

import type { FC, FormEventHandler } from 'react';
import React, { useCallback } from 'react';
Expand Down Expand Up @@ -34,7 +34,7 @@ const PredKeysSelect: FC<
});

return (
<InputWrapper label="Predicate" htmlFor={ELEMENT_ID}>
<FormFieldWrapper label="Predicate" htmlFor={ELEMENT_ID}>
<Select
{...rest}
id={ELEMENT_ID}
Expand All @@ -44,7 +44,7 @@ const PredKeysSelect: FC<
>
{options}
</Select>
</InputWrapper>
</FormFieldWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IInputProps, IInputWrapperProps } from '@kadena/react-ui';
import type { IFormFieldWrapperProps, IInputProps } from '@kadena/react-ui';
import { TextField } from '@kadena/react-ui';

import useTranslation from 'next-translate/useTranslation';
Expand All @@ -8,7 +8,7 @@ import type { FieldError } from 'react-hook-form';
import { publicKeyFieldStyles } from './styles.css';

interface IPublicKeyFieldProps
extends Partial<Omit<IInputWrapperProps, 'children'>> {
extends Partial<Omit<IFormFieldWrapperProps, 'children'>> {
inputProps: Partial<
Pick<
IInputProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { SystemIcon } from '@components/Icon';
import { Label } from '@components/Typography';
import type { FC } from 'react';
import React from 'react';
import { headerClass, infoClass, tagClass } from './InputHeader.css';
import { headerClass, infoClass, tagClass } from './FormFieldHeader.css';

export interface IInputHeaderProps {
export interface IFormFieldHeaderProps {
label: string;
htmlFor: string;
tag?: string;
info?: string;
}

export const InputHeader: FC<IInputHeaderProps> = ({
export const FormFieldHeader: FC<IFormFieldHeaderProps> = ({
label,
htmlFor,
tag,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { SystemIcon } from '@components/Icon';
import type { FC } from 'react';
import React from 'react';
import { helperClass, helperIconClass } from './InputHelper.css';
import { helperClass, helperIconClass } from './FormFieldHelper.css';

interface IInputHelperProps {
interface IFormFieldHelperProps {
children: React.ReactNode;
}

export const InputHelper: FC<IInputHelperProps> = ({ children }) => {
export const FormFieldHelper: FC<IFormFieldHelperProps> = ({ children }) => {
return (
<span className={helperClass}>
<span className={helperIconClass}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type { FormFieldStatus } from '../Form.css';

export type OpenSections = string[];

interface IInputWrapperContext {
interface IFormFieldWrapperContext {
status?: FormFieldStatus;
leadingTextWidth?: keyof typeof vars.sizes;
}

export const InputWrapperContext = createContext<IInputWrapperContext>({
export const FormFieldWrapperContext = createContext<IFormFieldWrapperContext>({
status: undefined,
leadingTextWidth: undefined,
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { statusColor, statusOutlineColor } from '../Form.css';
import {
helperIconColor,
helperTextColor,
} from './InputHelper/InputHelper.css';
} from './FormFieldHelper/FormFieldHelper.css';

const statusOptions: Record<FormFieldStatus, FormFieldStatus> = {
disabled: 'disabled',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import type { IInputWrapperProps } from '@components/Form';
import { Input, InputWrapper } from '@components/Form';
import type { IFormFieldWrapperProps } from '@components/Form';
import { FormFieldWrapper, Input } from '@components/Form';
import type { SystemIcon } from '@components/Icon';
import type { Meta, StoryObj } from '@storybook/react';
import { vars } from '@theme/vars.css';
import React from 'react';
import { statusVariant } from './InputWrapper.css';
import { statusVariant } from './FormFieldWrapper.css';

type StoryProps = {
helperText: string;
leadingText: string;
icon: keyof typeof SystemIcon;
rightIcon: keyof typeof SystemIcon;
} & IInputWrapperProps;
} & IFormFieldWrapperProps;

const meta: Meta<StoryProps> = {
title: 'Form/InputWrapper',
title: 'Form/FormFieldWrapper',
parameters: {
docs: {
description: {
component:
'The InputWrapper component is intended to be used to wrap one or more form input components to provide them with a shared and optional label, tag, info, helper text and status colors.',
'The FormFieldWrapper component is intended to be used to wrap one or more form input components to provide them with a shared and optional label, tag, info, helper text and status colors.',
},
},
},
Expand Down Expand Up @@ -113,7 +113,7 @@ export const Group: Story = {
leadingTextWidth,
}) => {
return (
<InputWrapper
<FormFieldWrapper
tag={tag}
info={info}
label={label}
Expand All @@ -135,7 +135,7 @@ export const Group: Story = {
disabled={disabled}
leadingText="Leading 2"
/>
</InputWrapper>
</FormFieldWrapper>
);
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type {
IInputProps,
ISelectProps,
ITextareaProps,
} from '@components/Form';
import type { FC, FunctionComponentElement } from 'react';
import React from 'react';
import type { vars } from 'src/styles';
import type { FormFieldStatus } from '../Form.css';

import { Stack } from '@components/Layout';
import type { IFormFieldHeaderProps } from './FormFieldHeader/FormFieldHeader';
import { FormFieldHeader } from './FormFieldHeader/FormFieldHeader';
import { FormFieldHelper } from './FormFieldHelper/FormFieldHelper';
import { FormFieldWrapperContext } from './FormFieldWrapper.context';
import { statusVariant } from './FormFieldWrapper.css';

export interface IFormFieldWrapperProps
extends Omit<IFormFieldHeaderProps, 'label'> {
children:
| FunctionComponentElement<IInputProps | ISelectProps | ITextareaProps>
| FunctionComponentElement<IInputProps | ISelectProps | ITextareaProps>[];
status?: FormFieldStatus;
disabled?: boolean;
helperText?: string;
label?: string;
leadingTextWidth?: keyof typeof vars.sizes;
}

export const FormFieldWrapper: FC<IFormFieldWrapperProps> = ({
status,
disabled,
children,
label,
leadingTextWidth = undefined,
htmlFor,
tag,
info,
helperText,
}) => {
const statusVal = disabled === true ? 'disabled' : status;

return (
<FormFieldWrapperContext.Provider value={{ status, leadingTextWidth }}>
<div className={statusVal ? statusVariant[statusVal] : undefined}>
{label !== undefined && (
<FormFieldHeader
htmlFor={htmlFor}
label={label}
tag={tag}
info={info}
/>
)}
<Stack gap="$2" direction="column">
{children}
</Stack>
{Boolean(helperText) && <FormFieldHelper>{helperText}</FormFieldHelper>}
</div>
</FormFieldWrapperContext.Provider>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
FormFieldWrapper,
type IFormFieldWrapperProps,
} from './FormFieldWrapper';
4 changes: 0 additions & 4 deletions packages/libs/react-ui/src/components/Form/Input/Input.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ export const disabledClass = style([
},
}),
{
opacity: 0.4,
selectors: {
'.inputGroup &': {
opacity: 1,
},
[`${darkThemeClass} &`]: {
backgroundColor: vars.colors.$gray60, // NOTE: this is to override the normal bg color
},
Expand Down
Loading

2 comments on commit cbdc36b

@vercel
Copy link

@vercel vercel bot commented on cbdc36b Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tools – ./packages/apps/tools

tools-kadena-js.vercel.app
kadena-js-transfer.vercel.app
tools.kadena.io
tools-git-main-kadena-js.vercel.app

@vercel
Copy link

@vercel vercel bot commented on cbdc36b Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-ui – ./packages/libs/react-ui

react-ui-delta.vercel.app
react-ui-kadena-js.vercel.app
react-ui-git-main-kadena-js.vercel.app
react-ui.kadena.io

Please sign in to comment.