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

Cannot respond to real-time theme color changes #104

Open
guxuerui opened this issue Jul 11, 2023 · 2 comments
Open

Cannot respond to real-time theme color changes #104

guxuerui opened this issue Jul 11, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@guxuerui
Copy link

When I try to make the modal background color change with the theme color, it always fails to update in real-time unless I refresh the page. What should I do?

My code:

let modalBg = 'rgba(255, 255, 255, 1)'
$: if ($currentTheme) {
  // currentTheme is a writable value, and I can get the right value after I change theme
  console.log('[src/routes/+layout.svelte:12] $currentTheme: ', $currentTheme)
  modalBg = $currentTheme === 'dark' ? 'rgba(31, 41, 55, 1)' : 'rgba(255, 255, 255, 1)'
  console.log('[src/routes/+layout.svelte:14] modalBg: ', modalBg)
}
<Modal
  closeButton={true}
  unstyled={false}
  styleWindow={{ width: "80%", backgroundColor: modalBg }}
>
  <slot />
</Modal>

Can anyone provide me with some assistance? Thank you very much.

@flekschas flekschas added the help wanted Extra attention is needed label Jan 10, 2024
@flekschas
Copy link
Owner

You might need to recreate the style object to have its reference change when modalBg changes. E.g.:

$: styleWindow = { width: "80%", backgroundColor: modalBg };

and assign styleWindow to the modal's styleWindow: <Modal styleWindow={styleWindow}>...</Modal>

@guxuerui
Copy link
Author

You might need to recreate the style object to have its reference change when modalBg changes. E.g.:

$: styleWindow = { width: "80%", backgroundColor: modalBg };

and assign styleWindow to the modal's styleWindow: <Modal styleWindow={styleWindow}>...</Modal>

OK,thanks for your reply~ I will try this again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants