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

Admin Generator (Future): Add support for startAdornments and endAdornments for form fields #2636

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

andrearutrecht
Copy link
Contributor

@andrearutrecht andrearutrecht commented Oct 16, 2024

Description

Added support for startAdornments and endAdornments for generated form fields.

Adornments started being added in #2612 and are now implemented for all fields where deemed useful.

As of right now, the following field types support adornments: text, number, numberRange, date

select and asyncSelect will be done in a follow-up PR: #2645

DatePicker changes: All DatePicker uses have been checked and do not lead to issues or errors.

Example

There are three ways to define an adornment: as just a string, an object with an icon name string or as an object with options.

Example with just a string:

{
    type: "number",
    name: "price",
    startAdornment: "€",
}

Example with an icon name:

{
    type: "date",
    name: "availableSince",
    startAdornment: { icon: "CalendarToday" },
}

Example with an object:

{
    type: "date",
    name: "availableSince",
    startAdornment: { icon: { name: "CalendarToday", color: "warning" }},
}

These lead to generated fields in the form like this:

{...}

<Field
    variant="horizontal"
    fullWidth
    name="priceRange"
    component={FinalFormRangeInput}
    label={<FormattedMessage id="product.priceRange" defaultMessage="Price Range" />}
    min={25}
    max={500}
    disableSlider
    startAdornment={
        <InputAdornment position="start">
            // <FormattedMessage id="priceRange.startAdornment" defaultMessage="€" /> // is not translatable anymore
           €
        </InputAdornment>
    }
/>

{...}

<Field
    variant="horizontal"
    fullWidth
    name="availableSince"
    component={FinalFormDatePicker}
    label={<FormattedMessage id="product.availableSince" defaultMessage="Available Since" />}
    startAdornment={
        <InputAdornment position="start">
            <CalendarTodayIcon />
        </InputAdornment>
    }
/>

{...}

<Field
    variant="horizontal"
    fullWidth
    name="availableSince"
    component={FinalFormDatePicker}
    label={<FormattedMessage id="product.availableSince" defaultMessage="Available Since" />}
    startAdornment={
        <InputAdornment position="start">
            <CalendarTodayIcon color="warning" />
        </InputAdornment>
    }
/>

{...}
  • I have verified if my change requires an example

Screenshots/screencasts

The Two examples from above are marked in the screenshot

Screenshot 2024-10-16 at 11 27 13 Screenshot 2024-10-16 at 13 34 19

Changeset

  • I have verified if my change requires a changeset

Related tasks and documents

https://vivid-planet.atlassian.net/browse/COM-1170

Open TODOs/questions

@nsams nsams requested a review from jamesricky October 16, 2024 17:33
nsams
nsams previously approved these changes Oct 17, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the changeset! However, we decided that we don't add changesets for the Admin Generator. So please remove/adapt it.

Comment on lines 25 to 26
startAdornment?: ReactNode;
endAdornment?: ReactNode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be added do the changeset I suppose. Also, aren't these props part of InputWithPopperProps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they are. I need to pay more attention to the existing props... Changeset will be updated.

@johnnyomair johnnyomair self-requested a review October 31, 2024 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants