Custom widgets can use the prefers-color-scheme ↗ CSS media feature to detect the color-scheme ↗ of the parent application and apply appropriate styles.
Additionally, the window.matchMedia() ↗ method can be used to detect the color scheme from JavaScript, for example to apply a theme to a component library.