Skip to content

feat: create modal component with radix-ui - #51070

Closed
Sboonny wants to merge 18 commits into
freeCodeCamp:mainfrom
Sboonny:feat/create-dialog-component
Closed

Sboonny wants to merge 18 commits into
freeCodeCamp:mainfrom
Sboonny:feat/create-dialog-component

Conversation

@Sboonny

@Sboonny Sboonny commented Jul 27, 2023 •

Copy link
Copy Markdown
Member

Checklist:

Closes #52922

@Sboonny
Sboonny requested a review from a team July 27, 2023 14:50
@github-actions github-actions Bot added the scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. label Jul 27, 2023
@ghost

ghost commented Jul 27, 2023 •

Copy link
Copy Markdown

👀 Review this PR in a CodeSee Review Map

View the CodeSee Map of this change

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@Sboonny
Sboonny marked this pull request as draft July 28, 2023 12:55
@github-actions github-actions Bot added scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. platform: api Server application that needs familiarity with Express, Fastify, MongoDB etc. platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: i18n language translation/internationalization. Often combined with language type label and removed scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. platform: api Server application that needs familiarity with Express, Fastify, MongoDB etc. platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: i18n language translation/internationalization. Often combined with language type label labels Aug 1, 2023
add the modal content

add radix react dialog

finish the styles for the content

add modal header
@ahmaxed

ahmaxed commented Oct 18, 2023

Copy link
Copy Markdown
Member

@Sboonny, is this ready for review? let me know if you would like me to take it from here.

@github-actions github-actions Bot added the platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. label Oct 18, 2023
@Sboonny

Sboonny commented Oct 18, 2023

Copy link
Copy Markdown
Member Author

Not yet, the styles need more fixing.

BTW, take a look at 2178edf, because Radix dialog is different from the bootstrap, and will require refactoring in the codebase, the transition from the components isn't smooth, are you okay with that?

@ahmaxed

ahmaxed commented Oct 18, 2023

Copy link
Copy Markdown
Member

The transition is fine, but the modal needs to have a way to open from the sagas as a lot of the logic lives there.

@Sboonny

Sboonny commented Oct 18, 2023 •

Copy link
Copy Markdown
Member Author

there is a prop in the Root aka the Modal, which should open it, it's called open, so if there are specific use cases in mind, it should enable it.

About the open sagas tho, my advice is to trim them, if you don't absolutely need them, so you can keep the context that related to the modal in your head as small as possible, and make changes to it later easier.

They may be used them for something I am not aware of, so it's up to you.

@ahmaxed

ahmaxed commented Oct 19, 2023

Copy link
Copy Markdown
Member

Refactoring the open modal logic from the sagas will take more time than creating a bootstrap modal clone.
So if radix modals(dialog), can be triggered using a prop from outside the modal component, we should be able to have multiple modal components similar to the current implementation and pop them based on redux state. Is that correct?

@Sboonny

Sboonny commented Oct 19, 2023

Copy link
Copy Markdown
Member Author

is the issue time?

Btw, it's possible, idk if it's the right approach, idk what happens to the focus when lost, so this will need to tested as well.

@ahmaxed

ahmaxed commented Oct 19, 2023

Copy link
Copy Markdown
Member

is the issue time?

Essentially that is why we are using radix/headlessui.

Btw, it's possible, idk if it's the right approach, idk what happens to the focus when lost, so this will need to be tested as well.

Well noted. I can take a look into it. Focus might be tricky as you mentioned.

@Sboonny

Sboonny commented Oct 20, 2023

Copy link
Copy Markdown
Member Author

if the issue is time, I will leave it to you how it is handled then, whether the refactoring is done in the following PR to reduce the complexity, or moved to contributors to handle it.

@github-actions github-actions Bot removed the platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. label Oct 21, 2023
@Sboonny
Sboonny marked this pull request as ready for review October 21, 2023 20:00
@Sboonny

Sboonny commented Oct 21, 2023 •

Copy link
Copy Markdown
Member Author

I have misused Modal.Content, it should have replaced how the old Modal looks. Now we have the old Modal through Modal.Layer, and the ability to show and hide it in local scope through Modal, Modal.Trigger, and Modal.Close. 👍

@raisedadead raisedadead added the MERGE CONFLICT! To be applied to PR's that have a merge conflict and need updating label Nov 4, 2023
@Sembauke Sembauke removed the MERGE CONFLICT! To be applied to PR's that have a merge conflict and need updating label Feb 28, 2024
@huyenltnguyen

huyenltnguyen commented Feb 29, 2024 •

Copy link
Copy Markdown
Member

So apparently the modal doesn't receive any custom CSS colors / classes, while Tailwind built-in classes are still working (see the border and the alignment):

Screenshot 2024-02-28 at 21 52 09 Screenshot 2024-02-29 at 22 38 47

What I've tried:

  • Changing the Portal container to storybook-root, so that the dialog is a child of storybook-root rather than a sibling (my theory was that only content inside of storybook-root can receive the styles)
    • ❌ Doesn't work
  • Importing colors.css to .storybook/preview.js
    • ❌ Doesn't work
  • Using the new Modal in /learn
    • ❌ Doesn't work. But this means the issue isn't in Storybook
  • Replacing radix-ui Dialog with headlessui Dialog
    • ❌ Doesn't work. But this means the issue isn't in radix-ui
  • Adding our own Button within the Modal
    • ❌ Doesn't work, and the Button has its color stripped off as well
  • Upgrading postcss-import 14 to 15
    • ❌ Doesn't work

I think this has something to do with our Tailwind config. For some reason Tailwind cannot generate the colors we need if their corresponding classes are used in a React Portal.

@ahmaxed

ahmaxed commented Mar 1, 2024

Copy link
Copy Markdown
Member

so the variables such as bg-background-secondary are defined within light-palette or dark-palette (theme-classes).
However, the modal is injected in the DOM outside of the the element that has the theme classes.

To illustrate, add the following to line 45 of the preview.js file.

  document.body.classList.add('light-palette');

To see the changes take effect better, change one of the modal elements background to --background-danger.

@huyenltnguyen

Copy link
Copy Markdown
Member

@ahmaxed You just saved me hours of debugging, thank you! I knew something was wrong with the portal placement but didn't think of the light-palette node (I also forgot that the color variables are mapped under this class).

radix-ui's Dialog does provide a prop for customizing the portal root, so we can move the portal under the light-palette div. Though I'll need to dig into the implementation approaches a bit further.

@ahmaxed

ahmaxed commented Mar 1, 2024

Copy link
Copy Markdown
Member

Glad to hear that. Looking forward to see how it looks in learn 🙌

@socket-security

Copy link
Copy Markdown

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

Package New capabilities Transitives Size Publisher
npm/@babel/[email protected] unsafe Transitive: environment, filesystem +41 14.4 MB nicolo-ribaudo
npm/@babel/[email protected] None 0 238 kB nicolo-ribaudo
npm/[email protected] None 0 4.85 kB dmnd
npm/[email protected] environment, shell Transitive: filesystem +15 208 kB sindresorhus
npm/[email protected] eval Transitive: environment, filesystem +3 757 kB vitaly
npm/[email protected] Transitive: environment, filesystem +1 576 kB vitaly
npm/[email protected] None 0 1.41 MB bnjmnt4n
npm/[email protected] environment +4 145 kB ljharb
npm/[email protected] filesystem +1 110 kB paulmillr

🚮 Removed packages: npm/@babel/[email protected], npm/@loadable/[email protected], npm/@playwright/[email protected], npm/@prisma/[email protected], npm/@radix-ui/[email protected], npm/@reach/[email protected], npm/@redux-saga/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@sentry/[email protected], npm/@sentry/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@storybook/[email protected], npm/@stripe/[email protected], npm/@stripe/[email protected], npm/@testing-library/[email protected], npm/@testing-library/[email protected], npm/@testing-library/[email protected], npm/@testing-library/[email protected], npm/@testing-library/[email protected], npm/@total-typescript/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@types/[email protected], npm/@typescript-eslint/[email protected], npm/@typescript-eslint/[email protected], npm/@uiw/[email protected], npm/@vitejs/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

@moT01 moT01 added the MERGE CONFLICT! To be applied to PR's that have a merge conflict and need updating label Mar 8, 2024
@huyenltnguyen huyenltnguyen changed the title feat: create modal component feat: create modal component with radix-ui Mar 11, 2024
@Sembauke Sembauke closed this Mar 11, 2024
@huyenltnguyen

Copy link
Copy Markdown
Member

This PR was closed in favor of #54044.

I did my best trying to make radix-ui work for us, but there were some limitations that made this Modal version incompatible with our usages in /learn (details in the linked PR). The alternative approach I went with is using headlessui's Dialog as the base.

@Sboonny Thank you again for the PR. Really appreciate the work you put in 🙂

@Sboonny
Sboonny deleted the feat/create-dialog-component branch March 11, 2024 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MERGE CONFLICT! To be applied to PR's that have a merge conflict and need updating scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UI Components] Create Modal component

6 participants