Custom Container
Control where the timepicker modal is rendered in the DOM
ui.appendTo
By default, the timepicker modal is appended to
document.body. Set ui.appendTo to a CSS selector or an element to render it inside another element. The picker looks a selector up with document.querySelector each time it opens, so the element must exist by then. A selector cannot point into a shadow root or another frame's document.Custom Container
#Append the modal to a specific container:
Within Modal Dialog
#Use inside a modal or dialog component:
index.ts
import { TimepickerUI } from 'timepicker-ui';// HTML:// <div class="modal" id="appointment-modal">// <div class="modal-content" id="modal-content">// <h2>Schedule Appointment</h2>// <input id="timepicker" type="text" />// </div>// </div>const input = document.querySelector('#timepicker');const picker = new TimepickerUI(input, {// Append to modal content instead of bodyui: { appendTo: '#modal-content' }});picker.create();
React
#Render the container in your component and pass its selector. Create the picker in an effect, so it only runs in the browser:
index.tsx
import { useEffect, useRef } from 'react';import { TimepickerUI } from 'timepicker-ui';function TimepickerWithContainer() {const inputRef = useRef<HTMLInputElement>(null);useEffect(() => {if (!inputRef.current) return;const picker = new TimepickerUI(inputRef.current, {ui: { appendTo: '#timepicker-root' }});picker.create();return () => {picker.destroy();};}, []);return (<><input ref={inputRef} type="text" /><div id="timepicker-root" /></>);}
Iframe Integration
#Load timepicker-ui in the iframe's own page. The modal is appended to that document's body, so it stays inside the frame:
index.ts
// Script running inside the iframe pageimport { TimepickerUI } from 'timepicker-ui';const input = document.querySelector('#timepicker');const picker = new TimepickerUI(input);picker.create();
Scoped Styles
#Use custom container with scoped CSS:
index.ts
import { TimepickerUI } from 'timepicker-ui';// HTML:// <div class="custom-scope" id="scoped-container">// <input id="timepicker" type="text" />// </div>const input = document.querySelector('#timepicker');const picker = new TimepickerUI(input, {ui: {appendTo: '#scoped-container',cssClass: 'scoped-picker'}});picker.create();// CSS: the modal now sits inside .custom-scope,// so rules scoped to it reach the picker// .custom-scope .tp-ui-wrapper.scoped-picker {// --tp-primary: #0b57d0;// }
Multiple Containers
#Different pickers in different containers:
index.ts
import { TimepickerUI } from 'timepicker-ui';// Picker 1 in sidebarconst input1 = document.querySelector('#timepicker-1');const picker1 = new TimepickerUI(input1, {ui: { appendTo: '#sidebar-container' }});picker1.create();// Picker 2 in main contentconst input2 = document.querySelector('#timepicker-2');const picker2 = new TimepickerUI(input2, {ui: { appendTo: '#main-content' }});picker2.create();// Picker 3 in modalconst input3 = document.querySelector('#timepicker-3');const picker3 = new TimepickerUI(input3, {ui: { appendTo: '#modal-dialog' }});picker3.create();