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

feat(Slug): Add slug prop to TextInput, TextArea, NumberInput, and DatePicker, add revert functionality to Slug #15115

Merged

Conversation

tw15egan
Copy link
Collaborator

@tw15egan tw15egan commented Nov 6, 2023

Closes #15089

Adds in a slug prop for TextInput, TextArea, DatePickerInput, and NumberInput

General usage would look like the following:

const slug = (
  <Slug>
    <SlugContent>
      <div>
        <p className="secondary">AI Explained</p>
        <h1>84%</h1>
        <p className="secondary bold">Confidence score</p>
        <p className="secondary">
          Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed do
          eiusmod tempor incididunt ut fsil labore et dolore magna aliqua.
        </p>
        <hr />
        <p className="secondary">Model type</p>
        <p className="bold">Foundation model</p>
      </div>
      <SlugActions>
        <IconButton kind="ghost" label="View">
          <View />
        </IconButton>
        <IconButton kind="ghost" label="Open Folder">
          <FolderOpen />
        </IconButton>
        <IconButton kind="ghost" label="Folders">
          <Folders />
        </IconButton>
        <Button>View literature</Button>
      </SlugActions>
    </SlugContent>
  </Slug>
);

<TextInput {...TextInputProps} slug={slug} />

Changelog

New

  • slug prop added so a user can pass down a Slug component to be rendered inside a form element
  • <Slug> has been updated to include two new props, revertActive and onRevertClick
    • revertActive props is to toggle the state of the Slug
    • onRevertClick is a callback function so that a user can restore the state of the edited input to whatever the stored AI content is

Example usage:

const textInputRef = useRef();
const aiValue = 'Generated AI content';
const [isEdited, setIsEdited] = useState(false);

const handleRevertClick = (evt) => {
 setIsEdited(false);
 textInputRef.current.focus();
 textInputRef.current.value = aiValue;
};

const handleChange = (evt) => {
 setIsTextInputEdited(true);
}

const slug = (
 <Slug revertActive={isTextInputEdited} onRevertClick={handleRevertClick}>
   {/* Slug content here */}
</Slug>
);


return (<TextInput ref={textInputRef slug={slug} defaultValue={aiValue} onChange={handleChange} />);

2023-11-13 20 10 40

Changed

  • Refactored TextArea .tsx file to match the general file structure found in other component files.
  • Reduced default gradient to 33%
  • Added a useEffect to NumberInput.tsx to trigger an update when the revert button is clicked to set the value back to the defaultValue that was passed in.

Removed

  • Removed outdated Slug.js file (replaced with index.js)
  • Removed outdated redo.svg and undo.svg at 16, 20, 24 that were being displayed rather than the correct asset, the 32 one.

Testing / Reviewing

Go to Form --> AI Form to see an example of the Slug rendered inside the form inputs. This seems like a clean approach that will not expand the surface area too much across the repo and can be achieved with minimal new styles per component. Form --> Revert Test is a sandbox to test the onRevertClick functionality.

Copy link

netlify bot commented Nov 6, 2023

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit 75ee611
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/655514025f496c00088db835
😎 Deploy Preview https://deploy-preview-15115--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Nov 6, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 1ff3829
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/654d2d6f41abed000840d746
😎 Deploy Preview https://deploy-preview-15115--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tw15egan tw15egan force-pushed the slug-implementation-exploration branch from d6ad6f6 to f5515ca Compare November 7, 2023 18:57
@tw15egan tw15egan force-pushed the slug-implementation-exploration branch from f5515ca to b3959d3 Compare November 7, 2023 19:03
@@ -164,12 +170,26 @@ const TextArea = React.forwardRef((props: TextAreaProps, forwardRef) => {
);
const { current: textAreaInstanceId } = useRef(getInstanceId());

const textareaRef = useRef<HTMLTextAreaElement>(null);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored this file a bit since it was quite scattered. I've basically moved all refs to the top, followed by effects, then class variable declarations, then normalized JSX elements. The only net new code is L222, L320, and L345

@tw15egan
Copy link
Collaborator Author

tw15egan commented Nov 9, 2023

@tay1orjones this PR is in a good spot to take a look and see if we should keep going down this route

@aagonzales
Copy link
Member

@tw15egan I've noticed the formatting inside the callout is off.
image

@aagonzales
Copy link
Member

aagonzales commented Nov 10, 2023

Will AI-populated form input ever be in an invalid state? Warning state? If so, where does the Slug go? Is it hidden, or is it moved over?

I still don't know if an AI populated input could be invalid but if it does then I think this way would be the correct error states with both the slug and error icon.
image

@aagonzales
Copy link
Member

aagonzales commented Nov 10, 2023

How will the "Revert to AI Input" functionality work?

I am thinking of the "revert" as another state essentially. I drew up a little user flow of how I think it would work.

image

@tw15egan tw15egan requested review from laurenmrice and a team as code owners November 14, 2023 17:15
Copy link
Member

@aagonzales aagonzales left a comment

Choose a reason for hiding this comment

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

The revert icon looks like there's an extra 1px of padding on top of it. Can that be removed? The icon seems a little off centered.

image

Also can we move the revert button 8px to the right so the AI icon and revert icon line up. This is how they align at the moment.

image

Everything else looks good though!

@tw15egan
Copy link
Collaborator Author

@aagonzales fixed 👍🏻

Copy link
Member

@aagonzales aagonzales left a comment

Choose a reason for hiding this comment

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

Everything looks good to me now 👍 🎉

Copy link
Member

@alisonjoseph alisonjoseph left a comment

Choose a reason for hiding this comment

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

This looks great in Chrome, seeing z-index and positioning issues in firefox.

Screenshot 2023-11-15 at 9 55 02 AM Screenshot 2023-11-15 at 9 58 19 AM

@tw15egan
Copy link
Collaborator Author

tw15egan commented Nov 15, 2023

Of course, Firefox doesn't support the :has selector 🙃

layout.css.has-selector.enabled set to true in about:config fixes it. Let me see if I can change the logic a bit

No positioning was touched for Slug, it's just using autoAlign by default, but you can pass in whatever specific align you need to slug to override. Seems like that may be an issue with the Popover in general, I can see the same issues in Chrome at specific screensizes. I can also turn off autoAlign by default if that is a smoother solution, but will require positioning to be set.

@tw15egan
Copy link
Collaborator Author

@alisonjoseph doing a bit of digging, there isn't an alternative selector to :has that would make this easy to fix. However, it seems like support will be added in Firefox v121. Looking at their release notes, it seems like they release a new minor each month. Stable (v119.0) was released 10/24, v118.0 was released on 9/26, and v117.0 on 8/29. Given this seemingly monthly cadence, this means the :has support should land in Firefox stable at the end of December.

Do you think this is fine, given:

  • the experimental nature of these components
  • it can work behind a feature flag
  • Firefox usage is ~2% globally

v121.0a1 release notes

Copy link
Member

@alisonjoseph alisonjoseph left a comment

Choose a reason for hiding this comment

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

Yes, I think that's fine @tw15egan

@tay1orjones tay1orjones added this pull request to the merge queue Nov 15, 2023
Merged via the queue into carbon-design-system:main with commit 26831fe Nov 15, 2023
19 checks passed
tay1orjones pushed a commit to tay1orjones/carbon that referenced this pull request Nov 16, 2023
…, and `DatePicker`, add revert functionality to `Slug` (carbon-design-system#15115)

* feat(TextInput): support slug prop

* fix(TextInput): add types for slug prop

* refactor(Slug): remove old file, move demo to form story

* docs(Storybook): update form story

* feat(NumberInput): add slug to NumberInput

* refactor(NumberInput): remove pseudo elements and use box-shadow

* style(NumberInput): fix issue with z-index, add invalid styles

* feat(DatePicker): add slug prop to DatePickerInput

* feat(TextArea): add slug prop to TextArea

* test(snapshot): update snapshots

* fix(TextArea): remove console warning

* style(Fluid): adjust styles for fluid inputs

* docs(Storybook): fix ids

* fix(Slug): adjust positioning, add storybook controls

* fix(Storybook): add story styles to form example

* fix(Slug): adjust positioning when invalid, warning state

* style(Slug): adjust padding when slug is present

* docs(Storybook): add examples with revert functionality

* fix(NumberInput): fix type error

* refactor(storybook): adjust stories

* feat(Slug): add revertLabel prop

* fix(Undo): replace undo, redo with coreect asset

* fix(Slug): adjust revert positioning, remove margin

* fix(NumberInput): don't set defaultValue if not provided, remove console

* chore(files): add ai-gradient to react package

* test(snapshot): update snapshots
@tay1orjones tay1orjones mentioned this pull request Nov 16, 2023
danoro96 pushed a commit to danoro96/carbon that referenced this pull request Jan 18, 2024
…, and `DatePicker`, add revert functionality to `Slug` (carbon-design-system#15115)

* feat(TextInput): support slug prop

* fix(TextInput): add types for slug prop

* refactor(Slug): remove old file, move demo to form story

* docs(Storybook): update form story

* feat(NumberInput): add slug to NumberInput

* refactor(NumberInput): remove pseudo elements and use box-shadow

* style(NumberInput): fix issue with z-index, add invalid styles

* feat(DatePicker): add slug prop to DatePickerInput

* feat(TextArea): add slug prop to TextArea

* test(snapshot): update snapshots

* fix(TextArea): remove console warning

* style(Fluid): adjust styles for fluid inputs

* docs(Storybook): fix ids

* fix(Slug): adjust positioning, add storybook controls

* fix(Storybook): add story styles to form example

* fix(Slug): adjust positioning when invalid, warning state

* style(Slug): adjust padding when slug is present

* docs(Storybook): add examples with revert functionality

* fix(NumberInput): fix type error

* refactor(storybook): adjust stories

* feat(Slug): add revertLabel prop

* fix(Undo): replace undo, redo with coreect asset

* fix(Slug): adjust revert positioning, remove margin

* fix(NumberInput): don't set defaultValue if not provided, remove console

* chore(files): add ai-gradient to react package

* test(snapshot): update snapshots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add AI enhancements to React TextInput, TextArea, NumberInput, and DatePicker
4 participants