{"id":23479565,"url":"https://github.com/Stanko/dual-range-input","last_synced_at":"2025-08-27T08:32:01.752Z","repository":{"id":263066529,"uuid":"889244456","full_name":"Stanko/dual-range-input","owner":"Stanko","description":"Native dual range input in 80 lines of TypeScript.","archived":false,"fork":false,"pushed_at":"2024-12-13T16:20:09.000Z","size":85,"stargazers_count":124,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2024-12-13T17:37:28.547Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://muffinman.io/dual-range-input/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stanko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-15T22:26:56.000Z","updated_at":"2024-12-13T16:20:13.000Z","dependencies_parsed_at":"2024-11-15T23:25:34.380Z","dependency_job_id":"09009727-a447-4000-8c8b-f83173c5d747","html_url":"https://github.com/Stanko/dual-range-input","commit_stats":null,"previous_names":["stanko/dual-range-input"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stanko%2Fdual-range-input","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stanko%2Fdual-range-input/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stanko%2Fdual-range-input/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stanko%2Fdual-range-input/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stanko","download_url":"https://codeload.github.com/Stanko/dual-range-input/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231145298,"owners_count":18334634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-24T19:31:41.078Z","updated_at":"2025-08-27T08:32:01.699Z","avatar_url":"https://github.com/Stanko.png","language":"TypeScript","funding_links":[],"categories":["SCSS"],"sub_categories":[],"readme":"# Native Dual-range Input\n\nThe native part is somewhat open for discussion - the library uses two native range inputs\nand about [sixty lines of JavaScript](https://cdn.jsdelivr.net/npm/@stanko/dual-range-input/dist/index.js) to make them work together.\nIn my book, it is _native enough_.\n\nIf you are interested in how it works, please check the [blog post](https://muffinman.io/blog/native-dual-range-input).\n\n## Usage\n\nInstall it:\n\n```bash\nnpm install @stanko/dual-range-input\n```\n\nAdd the required markup:\n\n```html\n\u003cdiv class=\"dual-range-input\"\u003e\n  \u003cinput type=\"range\" min=\"0\" max=\"100\" step=\"1\" value=\"25\" id=\"min\" /\u003e\n  \u003cinput type=\"range\" min=\"0\" max=\"100\" step=\"1\" value=\"75\" id=\"max\" /\u003e\n\u003c/div\u003e\n```\n\nImport the CSS file located at:\n\n```\n./node_modules/@stanko/dual-range-input/dist/index.css\n```\n\nInstantiate the library:\n\n```js\nimport DualRangeInput from '@stanko/dual-range-input';\n\nconst $min = document.querySelector('#min');\nconst $max = document.querySelector('#max');\n\nnew DualRangeInput($min, $max);\n\n// Add native event handlers\n$min.addEventListener('input', () =\u003e {\n  // ...\n});\n```\n\n### Parameters\n\n- **$min** `HTMLInputElement` - The range input element for the minimum value\n- **$max** `HTMLInputElement` - The range input element for the maximum value\n- **precision** `number`, optional, defaults to 3 - The number of decimal places to round the mid value to\n\n## Styling\n\nStyles are controlled using CSS variables.\n\nHere are all of the variables and their default values:\n\n```css\n/* Height of the input */\n--dri-height: 1.5rem;\n\n/* Thumb size */\n--dri-thumb-width: 1.25rem;\n--dri-thumb-height: 1.25rem;\n\n/* Thumb background color */\n--dri-thumb-color: #ddd;\n--dri-thumb-hover-color: #a8d5ff;\n--dri-thumb-active-color: #4eaaff;\n\n/* Thumb border */\n--dri-thumb-border-color: rgba(0, 0, 0, 0.1);\n--dri-thumb-border-hover-color: var(--dri-thumb-border-color);\n--dri-thumb-border-active-color: var(--dri-thumb-border-color);\n--dri-thumb-border-radius: 1rem;\n--dri-thumb-border-width: 1px;\n\n/* Track size */\n--dri-track-height: 0.25rem;\n--dri-track-border-radius: 1rem;\n\n/* Track color */\n--dri-track-color: #ccc;\n--dri-track-filled-color: #0084ff;\n/* Optional to create a gradient */\n--dri-track-filled-gradient-mid-color: var(--dri-track-filled-color);\n--dri-track-filled-gradient-end-color: var(--dri-track-filled-color);\n```\n\nPlease note that `--dri-thumb-width` is used by the library through the CSS `calc()` methods.\n\n### Custom theme\n\nTo create your own theme, just change the variables. For example here is code for the purple example from the demo page:\n\n```scss\n.dual-range-input--purple {\n  --dri-thumb-width: 2rem;\n  --dri-thumb-height: 2rem;\n\n  --dri-thumb-color: #ddd;\n  --dri-thumb-active-color: #682af8;\n  --dri-thumb-hover-color: #b697ff;\n\n  --dri-track-filled-color: #682af8;\n\n  --dri-height: 2rem;\n}\n```\n\nThis gives you:\n\n![Dual range input styled in purple](./purple-example.png)\n\nYou can find more examples in the [demo SCSS file](./demo/index.scss).\n\n### :focus-visible styles\n\nThese are the default focus styles, feel free to override them.\n\n```scss\n.dual-range-input:has(input:focus-visible) {\n  outline: 2px solid var(--dri-thumb-active-color);\n  outline-offset: 4px;\n  border-radius: 4px;\n}\n```\n\n## API\n\n- `update(method: 'floor' | 'ceil' = 'ceil')`\n\n  The main method that updates the mid-point and the gradient fill. You should call it only when you make direct changes to one of the input's value.\n\n  `method` is the rounding method used for the mid-point. It is used only when the midpoint falls between two tickmarks. In the case of direct value changes, this doesn't matter much. However, the library uses `ceil` when the minimum input is updated and `floor` when the maximum input is updated.\n\n  ```js\n  const priceInput = new DualRangeInput($min, $max);\n\n  $min.value = 20;\n  priceInput.update('ceil');\n\n  $max.value = 37;\n  priceInput.update('floor');\n  ```\n\n- `destroy()`\n\n  Removes event listeners set by the library.\n\n  ```js\n  const priceInput = new DualRangeInput($min, $max);\n\n  priceInput.destroy();\n  ```\n\n## WebComponent\n\nFor now, for those who prefer WebComponents, here is a simple example:\n\n```js\nimport DualRangeInput from '@stanko/dual-range-input';\n\nclass DualRangeInputWebComponent extends HTMLElement {\n  constructor() {\n    super();\n\n    const $min = this.querySelector('input[type=range]:first-child');\n    const $max = this.querySelector('input[type=range]:nth-child(2)');\n\n    new DualRangeInput($min, $max);\n  }\n}\n\ncustomElements.define('dual-range-input', DualRangeInputWebComponent);\n```\n\n## TODO\n\n- [x] Remove highlight on tap, on mobile\n- [x] Update readme\n- [x] Publish the package\n- [x] RTL\n- [x] Write a blog post\n- [ ] Add (p)react version\n- [ ] Explore web component approach\n\n## Other\n\n- Library is only available as ESM module.\n- Library doesn't include border around the track, it just feels too hacky. But here is the code if you want to use it:\n\n  ```scss\n  .dual-range-input {\n    --dri-track-border-color: #ccc;\n    position: relative;\n\n    \u0026::before {\n      content: '';\n      display: block;\n      position: absolute;\n      background-color: var(--dri-track-border-color);\n      border-radius: var(--dri-track-border-radius);\n      // Make it stick 1px on each side\n      height: calc(var(--dri-track-height) + 2px);\n      left: -1px;\n      right: -1px;\n      // Center it vertically\n      top: 50%;\n      transform: translateY(-50%);\n    }\n\n    input {\n      // Put the inputs above it\n      position: relative;\n      z-index: 1;\n    }\n  }\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStanko%2Fdual-range-input","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStanko%2Fdual-range-input","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStanko%2Fdual-range-input/lists"}