-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forward ruby enumeration demo params with dark mode
A bit convoluted here, but continuing down this path of keeping the demo JS in a separate repo: we want to request an iframe URL with query params with color scheme choices. Dark mode is not kept on the server at the moment, so I use a Stimulus controller to set the final turbo frame url on the frontend which is later converted to the appropriate iframe url on the backend. Send query params from Ruby to JS to Ruby to JS!!!
- Loading branch information
Showing
6 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
|
||
import { debug } from '../../utils'; | ||
import { isDarkMode } from '../darkmode'; | ||
|
||
const console = debug('app:javascript:controllers:demos:ruby-enumeration'); | ||
|
||
export default class extends Controller { | ||
static values = { | ||
url: String, | ||
}; | ||
|
||
connect() { | ||
console.log('connect'); | ||
|
||
const turboFrame = this.element; | ||
const url = new URL(this.urlValue); | ||
|
||
// Determine if the page is in Dark Mode | ||
url.searchParams.append('is_dark_mode', isDarkMode()); | ||
|
||
console.log('url', url.toString()); | ||
|
||
// Set the src attribute of the Turbo Frame element | ||
turboFrame.src = url.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters