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

UI: Create new form elements in the new Core UI (Input, TextArea, Select) #23469

Merged
merged 9 commits into from
Jul 18, 2023

Conversation

cdedreuille
Copy link
Contributor

@cdedreuille cdedreuille commented Jul 16, 2023

What I did

As part of the work of moving components to Core UI, I'm creating 3 new components:

  • Input
  • TextArea
  • Select

These components are now primitives and not sub components of the Form component. For context, we are depreciating the Form component in favour of better primitives. In term of design, nothing is changing except for the fact that by default all of these component will be 100% in width.

How to test

  1. Got to the Core UI Storybook
  2. Test the new components

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests)
  • Make sure to add/update documentation regarding your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts
  • Make sure this PR contains one of the labels below.

["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

@cdedreuille cdedreuille added ui maintenance User-facing maintenance tasks ci:normal labels Jul 16, 2023
@cdedreuille cdedreuille changed the base branch from next to release/7.2 July 16, 2023 21:33
@github-actions
Copy link
Contributor

Fails
🚫

PR is not labeled with one of: ["patch:no","patch:yes"]

Generated by 🚫 dangerJS against 312c23f

@GadiZimerman
Copy link

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Analysis

  • 🎯 Main theme: Creation of new UI form elements
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • Focused PR: Yes, the PR is focused as it clearly states the creation of new UI form elements (TextField, TextArea, Select) as part of the work of moving components to Core UI.
  • 🔒 Security concerns: No, the PR does not introduce any obvious security concerns as it mainly deals with UI components.

PR Feedback

  • 💡 General PR suggestions: The PR is well-structured and the code is clean. However, it would be beneficial to add tests for the new components to ensure they work as expected. Also, it would be good to add some error handling or input validation for the form fields.

How to use

Tag me in a comment '@CodiumAI-Agent' and add one of the following commands:
/review - Request a review of the latest update to the PR.
/describe - Modify the PR title and description based on the contents of the PR.
/improve - Suggest improvements to the code in the PR. These will be provided as pull request comments, ready to commit.
/ask - Pose a question about the PR.

import React, { forwardRef } from 'react';
import { styled } from '@storybook/theming';

interface InputProps {

Choose a reason for hiding this comment

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

Consider adding PropTypes for better type checking and to make the code more self-documenting. [medium]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

euh ... no.

export default meta;
type Story = StoryObj<typeof Input>;

export const Base: Story = {

Choose a reason for hiding this comment

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

Consider adding more diverse storybook examples to cover different use cases and edge cases. [medium]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting one. I could do that.

@cdedreuille cdedreuille changed the title UI: Create new form elements in the new Core UI (TextField, TextArea, Select) UI: Create new form elements in the new Core UI (Input, TextArea, Select) Jul 16, 2023
@cdedreuille cdedreuille marked this pull request as ready for review July 18, 2023 14:57
@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@radix-ui/react-select 1.2.2 None +70 2.82 MB benoitgrelard

export const Base: Story = {
args: {},
render: (_, { args }) => (
<div style={{ width: 400 }}>
Copy link
Member

Choose a reason for hiding this comment

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

Let's put this in a decorator, though I'm not a fan of arbitrary wrappers for widths.
I guess we don't want to use viewports here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's really just to test it inside a container. By default it is width 100%

Comment on lines +65 to +74
export const Select = {
Root: SelectPrimitive.Root,
Group: SelectPrimitive.Group,
Value: SelectPrimitive.Value,
Trigger: SelectTrigger,
Content: SelectContent,
Label: SelectLabel,
Item: SelectItem,
Separator: SelectSeparator,
};
Copy link
Member

Choose a reason for hiding this comment

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

For complex combination-components like these JSdoc comments with mini examples would be great.

That way when users import these, all they have to do to get a example snippet, is hover over this import.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a wrapper on top of Radix with styles added to it. I can improve the docs to specify that I guess to make sure they go to Radix to understand all the use cases. We will not try to recreate their docs.

Comment on lines +5 to +8
interface SelectItemProps {
children: React.ReactNode;
value: string;
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a lie, it's actually much much more.

ComponentProps<typeof StyledItem>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I can replace it with that type.

return <StyledTextarea ref={ref} {...props} />;
});

Textarea.displayName = 'Textarea';
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it's a forwardRef with an arrow function inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is needed to make sure React devtools function correctly. This triggers an error otherwise.


SelectItem.displayName = 'SelectItem';

const StyledItem = styled(RadixSelect.Item)(({ theme }) => ({
Copy link
Member

Choose a reason for hiding this comment

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

You're not actually using the theme in this component?

},
}));

const StyledItemIndicator = styled(RadixSelect.ItemIndicator)(({ theme }) => ({
Copy link
Member

Choose a reason for hiding this comment

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

You're not actually using the theme in this component?

overflow: 'hidden',
backgroundColor: theme.input.background,
borderRadius: '6px',
border: theme.base === 'dark' ? `1px solid ${theme.input.border}` : 'none',
Copy link
Member

Choose a reason for hiding this comment

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

Interesting choice to have no border at all in dark-mode. Can you elaborate?
Would a 1px solid transparent not be better? Less layout shifts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can't have any layout shift since it will close the panel when you click anywhere else but you're right just to be safe we can add 1px solid transparent

import React, { forwardRef } from 'react';
import { styled } from '@storybook/theming';

interface InputProps {
Copy link
Member

Choose a reason for hiding this comment

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

This is a lie, it's actually more!

ComponentProps<typeof StyledInput>

Comment on lines +10 to +12
export const Input = forwardRef<HTMLInputElement, InputProps>(({ ...props }, ref) => {
return <StyledInput ref={ref} {...props} />;
});
Copy link
Member

Choose a reason for hiding this comment

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

{ ...props } does not make any sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@cdedreuille cdedreuille merged commit 53276b5 into release/7.2 Jul 18, 2023
@cdedreuille cdedreuille deleted the charles/update-form-ui branch July 18, 2023 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:normal maintenance User-facing maintenance tasks ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants