Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Input now support refs #123

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
abc7936
Allows our Input to be used with Refs the same way as native Antd Inp…
tibuurcio Mar 1, 2024
1de8722
Formatting
tibuurcio Mar 1, 2024
236681b
Merge branch 'main' into fix/input-forward-ref
tibuurcio Mar 14, 2024
f4c6f0e
Remove some unrelated stuff from this branch
tibuurcio Mar 14, 2024
8e808b8
Allows our Input to be used with Refs the same way as native Antd Inp…
tibuurcio Mar 1, 2024
35df00c
Formatting
tibuurcio Mar 1, 2024
65917fc
Remove some unrelated stuff from this branch
tibuurcio Mar 14, 2024
65d3846
Merge remote-tracking branch 'origin/fix/input-forward-ref' into fix/…
tibuurcio Mar 15, 2024
1c82b57
Commit generated CSS
tibuurcio Mar 15, 2024
2f111d5
Removes formatting changes
tibuurcio Mar 15, 2024
273fd0f
Merge branch 'fix/input-forward-ref' of https://github.com/mParticle/…
tibuurcio Mar 15, 2024
746eb3f
Commit generated CSS
tibuurcio Mar 15, 2024
f03f4f4
refactor: changes the usage of Inputs to come from the aquarium
tibuurcio Mar 15, 2024
7cc7e90
Merge branch 'fix/input-forward-ref' of https://github.com/mParticle/…
tibuurcio Mar 15, 2024
f719332
Commit generated CSS
tibuurcio Mar 15, 2024
1d38bff
Merge branch 'main' into fix/input-forward-ref
jared-dickman Mar 19, 2024
3862fe2
Commit generated CSS
jared-dickman Mar 19, 2024
155b0fe
Allows our Input to be used with Refs the same way as native Antd Inp…
tibuurcio Mar 1, 2024
7f7fb5c
Formatting
tibuurcio Mar 1, 2024
5793d41
Remove some unrelated stuff from this branch
tibuurcio Mar 14, 2024
a8b0668
Allows our Input to be used with Refs the same way as native Antd Inp…
tibuurcio Mar 1, 2024
f4a9a95
Remove some unrelated stuff from this branch
tibuurcio Mar 14, 2024
361d2ab
Removes formatting changes
tibuurcio Mar 15, 2024
b956008
refactor: changes the usage of Inputs to come from the aquarium
tibuurcio Mar 15, 2024
d4dbfc2
Merge branch 'fix/input-forward-ref' of https://github.com/mParticle/…
tibuurcio Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"semi": false,
"singleQuote": true,
"arrowParens": "avoid",
"printWidth": 120,
"bracketSameLine": true
"printWidth": 120
}
2 changes: 1 addition & 1 deletion design/LightTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ export const LightTheme: IMpThemeConfig = {
mpColorBorderDisabled: '#dcdcd8',
},
},
}
}
66 changes: 65 additions & 1 deletion src/components/data-entry/Input/Input.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Input } from 'src/components/data-entry/Input/Input'
import { Input, type InputRef } from 'src/components/data-entry/Input'
import { Button } from 'src/components/general/Button/Button'
import { type Meta, type StoryObj } from '@storybook/react'
import { ExampleStory } from 'src/utils/ExampleStory'
import { useRef } from 'react'
import { Space } from 'src/components'
import { expect, userEvent } from '@storybook/test'

const meta: Meta<typeof Input> = {
title: 'Aquarium/Data Entry/Input',
component: Input,
Expand Down Expand Up @@ -125,3 +131,61 @@ export const WithPrefixAndSuffix: Story = {
placeholder: 'Email',
},
}

export const WithFocusManagement: Story = {
args: {
value: 'Test value',
},
render: (props, meta) => {
const inputRef = useRef<InputRef>(null)

const focus = (cursor: 'start' | 'end' | 'all' = 'start') => {
inputRef.current?.focus({
cursor,
})
}

return (
<ExampleStory title={meta.name}>
<Space direction="vertical" style={{ width: '100%' }}>
<Space wrap>
<Button
onClick={() => {
focus('start')
}}>
Focus at start
</Button>
<Button
onClick={() => {
focus('end')
}}>
Focus at last
</Button>
<Button
onClick={() => {
focus('all')
}}>
Focus to select all
</Button>
</Space>
<br />
<Input {...props} defaultValue="Welcome to the Aquarium" ref={inputRef} />
</Space>
</ExampleStory>
)
},
play: async story => {
const input = story.canvasElement.querySelector('input')
await expect(input).toBeInTheDocument()

const buttons = story.canvasElement.querySelectorAll('button')
await expect(buttons.length).toBe(3)

for (const button of buttons) {
input?.blur()
await userEvent.click(button)
await expect(input).toHaveFocus()
input?.blur()
}
},
}
11 changes: 5 additions & 6 deletions src/components/data-entry/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import { Input as AntInput } from 'antd'
import { type InputProps as AntInputProps } from 'antd'
import { ConfigProvider } from 'src/components'
import { type InputRef } from 'antd'
import { forwardRef, type Ref } from 'react'

export interface IInputProps extends AntInputProps {}

export { type InputRef }

export const Input = (props: IInputProps) => {
const Input = (props: IInputProps, ref: Ref<InputRef>) => {
return (
<ConfigProvider>
<AntInput {...props} />
<AntInput {...props} ref={ref} />
</ConfigProvider>
)
}

Input.Group = AntInput.Group
Input.Password = AntInput.Password
Input.Search = AntInput.Search
Input.TextArea = AntInput.TextArea
Comment on lines -18 to -21
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Try to keep this in the Input file if we can.

const InputWithRef = forwardRef(Input)
export { InputWithRef as InternalInput }
19 changes: 19 additions & 0 deletions src/components/data-entry/Input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { type ForwardRefExoticComponent, type RefAttributes } from 'react'
import { Input as AntInput, type InputRef } from 'antd'
import { InternalInput, type IInputProps } from 'src/components/data-entry/Input/Input'

type CompoundedComponent = ForwardRefExoticComponent<IInputProps & RefAttributes<InputRef>> & {
Group: typeof AntInput.Group
Search: typeof AntInput.Search
TextArea: typeof AntInput.TextArea
Password: typeof AntInput.Password
}

const Input = InternalInput as CompoundedComponent

Input.Group = AntInput.Group
Input.Password = AntInput.Password
Input.Search = AntInput.Search
Input.TextArea = AntInput.TextArea

export { Input, type InputRef, type IInputProps }
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious why we need an index for Input only, cant this go in src/components/index?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm testing these to see if we can use the already present index

9 changes: 6 additions & 3 deletions src/components/data-entry/Mentions/Mentions.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,15 @@ export const ExampleForm: Story = {
layout="horizontal"
onFinish={() => {
void onFinish()
}}>
}}
>
<Form.Item
name="coders"
label="Top coders"
labelCol={{ span: 6 }}
wrapperCol={{ span: 16 }}
rules={[{ validator: checkMention }]}>
rules={[{ validator: checkMention }]}
>
<Mentions
rows={1}
options={[
Expand All @@ -279,7 +281,8 @@ export const ExampleForm: Story = {
label="Bio"
labelCol={{ span: 6 }}
wrapperCol={{ span: 16 }}
rules={[{ required: true }]}>
rules={[{ required: true }]}
>
<Mentions
rows={3}
placeholder="You can use @ to ref user here"
Expand Down
2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export { Slider, type ISliderProps } from './data-entry/Slider/Slider'
export { Cascader, type ICascaderProps } from './data-entry/Cascader/Cascader'
export { DatePicker, type IDatePickerProps } from './data-entry/DatePicker/DatePicker'
export { Checkbox, type ICheckboxProps } from './data-entry/Checkbox/Checkbox'
export { Input, type IInputProps } from './data-entry/Input/Input'
export { Input, type IInputProps, type InputRef } from './data-entry/Input'
export { InputNumber, type IInputNumberProps } from './data-entry/InputNumber/InputNumber'
export { Switch, type ISwitchProps } from './data-entry/Switch/Switch'
export { Upload, type IUploadProps } from './data-entry/Upload/Upload'
Expand Down
13 changes: 8 additions & 5 deletions src/components/layout/Flex/Flex.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const meta: Meta<typeof Flex> = {
height: 108,
borderRadius: 6,
border: '1px solid #40a9ff',
}}>
}}
>
{Array.from({ length: 4 }).map((_, i) => (
<div
key={i}
Expand Down Expand Up @@ -136,8 +137,9 @@ export const ExampleBasic: Story = {
<Radio.Group
value={value}
onChange={e => {
setValue(e.target.value)
}}>
setValue(e.target.value as string)
}}
>
<Radio value="horizontal">horizontal</Radio>
<Radio value="vertical">vertical</Radio>
</Radio.Group>
Expand Down Expand Up @@ -198,8 +200,9 @@ export const ExampleGap: Story = {
<Radio.Group
value={gapSize}
onChange={e => {
setGapSize(e.target.value)
}}>
setGapSize(e.target.value as SizeType | 'customize')
}}
>
{['small', 'middle', 'large', 'customize'].map(size => (
<Radio key={size} value={size}>
{size}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const GlobalNavigation = (props: IGlobalNavigationProps) => {
className="globalNavigation__mpHome"
onClick={() => {
props.onMpHomeClick()
}}>
}}
>
<MpLogo className="globalNavigation__mpSvg" />
</Center>
</Tooltip>
Expand All @@ -94,4 +95,4 @@ export const GlobalNavigation = (props: IGlobalNavigationProps) => {
</Layout.Sider>
</Layout>
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function NavigationSearch(props: INavigationSearchProps) {
<>Search</>
<>{getOS() === 'Macintosh' ? 'Cmd' : 'Ctrl'} + K</>
</Space>
}>
}
>
<Center className="globalNavigation__searchButtonWrapper">
<Button
className="globalNavigation__searchButton"
Expand Down
2 changes: 1 addition & 1 deletion src/components/navigation/GlobalNavigation/SuiteLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export function SuiteLogo(props: IGlobalNavigationLogo) {
{props.label}
</Center>
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type INavigationOrg,
type INavigationWorkspace,
type IWorkspaceSelectorDisplayItem,
type InputRef,
Popover,
} from 'src/components'
import { Flex } from 'src/components'
Expand All @@ -17,10 +18,6 @@ import { useEffect } from 'react'
import { useMemo } from 'react'
import { debounce, hasImageAtSrc } from 'src/utils/utils'
import { getInitials } from 'src/utils/utils'

// TODO: Need to make our Input component comply with forwardRef to be able to import it from src/components
Copy link
Collaborator

Choose a reason for hiding this comment

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

praise TODONE!

// As soon as https://github.com/mParticle/aquarium/pull/123 is merged
import { type InputRef } from 'antd'
import { WorkspaceSelectorContent } from 'src/components/navigation/GlobalNavigation/WorkspaceSelector/WorkspaceSelectorContent'
import { useMount } from 'src/hooks/useMount'
import { PaddingXxs } from 'src/styles/style'
Expand Down Expand Up @@ -151,12 +148,14 @@ export function WorkspaceSelector(props: IWorkspaceSelectorProps) {
signoutOptions={props.signoutOptions}
menuItems={menuItems}
/>
}>
}
>
<div
className="globalNavigation__item workspaceSelector__menuItem"
onClick={e => {
focusOnInput(true)
}}>
}}
>
<Avatar {...props.avatarOptions} className="workspaceSelector__avatar">
{getInitialsIfNoImage(hasImage, workspaceInitials)}
</Avatar>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type ChangeEvent, type RefObject } from 'react'
import { Input, type InputRef } from 'antd'
import type { IWorkspaceSelectorProps } from 'src/components/navigation/GlobalNavigation/WorkspaceSelector/WorkspaceSelector'
import type { IWorkspaceSelectorDisplayItem } from 'src/components'
import { Input, type InputRef, type IWorkspaceSelectorDisplayItem } from 'src/components'
import { WorkspaceSelectorContentItems } from 'src/components/navigation/GlobalNavigation/WorkspaceSelector/WorkspaceSelectorContentItems'
import { WorkspaceNoResults } from 'src/components/navigation/GlobalNavigation/WorkspaceSelector/WorkspaceNoResults'
import { WorkspaceSignout } from 'src/components/navigation/GlobalNavigation/WorkspaceSelector/WorkspaceSignout'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const WorkspaceSignout = ({ signoutOptions }: { signoutOptions: IWorkspac
type="primary"
onClick={_e => {
signoutOptions?.onSignout()
}}>
}}
>
{signoutOptions?.label ?? 'Sign Out of mParticle'}
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
.navigationCreate__item {
height: 100% !important;
min-height: 100% !important;
padding: var(--padding-xxs) 0;
padding: var(--padding-xxs) 0;
}

.navigationCreate__item .ant-flex {
Expand Down
48 changes: 20 additions & 28 deletions src/styles/_variables.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
:root {
--blue: #1677ff;
--purple: #722ed1;
--cyan: #13c2c2;
--green: #52c41a;
--magenta: #eb2f96;
--purple: #722ED1;
--cyan: #13C2C2;
--green: #52C41A;
--magenta: #EB2F96;
--pink: #eb2f96;
--red: #f5222d;
--orange: #fa8c16;
--yellow: #fadb14;
--volcano: #fa541c;
--geekblue: #2f54eb;
--gold: #faad14;
--lime: #a0d911;
--red: #F5222D;
--orange: #FA8C16;
--yellow: #FADB14;
--volcano: #FA541C;
--geekblue: #2F54EB;
--gold: #FAAD14;
--lime: #A0D911;
--color-primary: #3600d1;
--color-success: #52c41a;
--color-warning: #faad14;
Expand All @@ -20,8 +20,7 @@
--color-link: #1677ff;
--color-text-base: #0f0e0e;
--color-bg-base: #fff;
--font-family: 'GT America', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--font-family: 'GT America', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--font-family-code: 'Roboto Mono', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
--font-size: 14px;
--line-width: 1px;
Expand Down Expand Up @@ -357,11 +356,9 @@
--margin-lg: 24px;
--margin-xl: 32px;
--margin-xxl: 48px;
--box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);
--box-shadow-secondary: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12),
0 9px 28px 8px rgba(0, 0, 0, 0.05);
--box-shadow-tertiary: 0 1px 2px 0 rgba(0, 0, 0, 0.03), 0 1px 6px -1px rgba(0, 0, 0, 0.02),
0 2px 4px 0 rgba(0, 0, 0, 0.02);
--box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05) ;
--box-shadow-secondary: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05) ;
--box-shadow-tertiary: 0 1px 2px 0 rgba(0, 0, 0, 0.03), 0 1px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px 0 rgba(0, 0, 0, 0.02) ;
--screen-xs: 480px;
--screen-xs-min: 480px;
--screen-xs-max: 575px;
Expand All @@ -380,16 +377,11 @@
--screen-xxl: 1600px;
--screen-xxl-min: 1600px;
--box-shadow-popover-arrow: 2px 2px 5px rgba(0, 0, 0, 0.05);
--box-shadow-card: 0 1px 2px -2px rgba(0, 0, 0, 0.16), 0 3px 6px 0 rgba(0, 0, 0, 0.12),
0 5px 12px 4px rgba(0, 0, 0, 0.09);
--box-shadow-drawer-right: -6px 0 16px 0 rgba(0, 0, 0, 0.08), -3px 0 6px -4px rgba(0, 0, 0, 0.12),
-9px 0 28px 8px rgba(0, 0, 0, 0.05);
--box-shadow-drawer-left: 6px 0 16px 0 rgba(0, 0, 0, 0.08), 3px 0 6px -4px rgba(0, 0, 0, 0.12),
9px 0 28px 8px rgba(0, 0, 0, 0.05);
--box-shadow-drawer-up: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12),
0 9px 28px 8px rgba(0, 0, 0, 0.05);
--box-shadow-drawer-down: 0 -6px 16px 0 rgba(0, 0, 0, 0.08), 0 -3px 6px -4px rgba(0, 0, 0, 0.12),
0 -9px 28px 8px rgba(0, 0, 0, 0.05);
--box-shadow-card: 0 1px 2px -2px rgba(0, 0, 0, 0.16), 0 3px 6px 0 rgba(0, 0, 0, 0.12), 0 5px 12px 4px rgba(0, 0, 0, 0.09) ;
--box-shadow-drawer-right: -6px 0 16px 0 rgba(0, 0, 0, 0.08), -3px 0 6px -4px rgba(0, 0, 0, 0.12), -9px 0 28px 8px rgba(0, 0, 0, 0.05) ;
--box-shadow-drawer-left: 6px 0 16px 0 rgba(0, 0, 0, 0.08), 3px 0 6px -4px rgba(0, 0, 0, 0.12), 9px 0 28px 8px rgba(0, 0, 0, 0.05) ;
--box-shadow-drawer-up: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05) ;
--box-shadow-drawer-down: 0 -6px 16px 0 rgba(0, 0, 0, 0.08), 0 -3px 6px -4px rgba(0, 0, 0, 0.12), 0 -9px 28px 8px rgba(0, 0, 0, 0.05) ;
--box-shadow-tabs-overflow-left: inset 10px 0 8px -8px rgba(0, 0, 0, 0.08);
--box-shadow-tabs-overflow-right: inset -10px 0 8px -8px rgba(0, 0, 0, 0.08);
--box-shadow-tabs-overflow-top: inset 0 10px 8px -8px rgba(0, 0, 0, 0.08);
Expand Down
Loading