{"id":22105215,"url":"https://github.com/zhangyu1818/switch-button","last_synced_at":"2025-03-24T02:44:53.433Z","repository":{"id":51060093,"uuid":"183927201","full_name":"zhangyu1818/switch-button","owner":"zhangyu1818","description":"Ant Design style and reactivity switch button.","archived":false,"fork":false,"pushed_at":"2021-05-25T10:16:45.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T14:45:31.872Z","etag":null,"topics":["ant-design","button","switch","switch-button"],"latest_commit_sha":null,"homepage":"https://zhangyu1818.github.io/switch-button/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhangyu1818.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-28T15:40:15.000Z","updated_at":"2021-05-25T10:16:47.000Z","dependencies_parsed_at":"2022-09-16T07:51:37.615Z","dependency_job_id":null,"html_url":"https://github.com/zhangyu1818/switch-button","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyu1818%2Fswitch-button","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyu1818%2Fswitch-button/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyu1818%2Fswitch-button/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyu1818%2Fswitch-button/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhangyu1818","download_url":"https://codeload.github.com/zhangyu1818/switch-button/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245200675,"owners_count":20576673,"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":["ant-design","button","switch","switch-button"],"created_at":"2024-12-01T06:39:51.809Z","updated_at":"2025-03-24T02:44:53.414Z","avatar_url":"https://github.com/zhangyu1818.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# switch-button \n![npm-version](https://img.shields.io/npm/v/switch-button.svg)\n[![codecov](https://codecov.io/gh/zhangyu1818/switch-button/branch/main/graph/badge.svg?token=XMOY7SVSJ4)](https://codecov.io/gh/zhangyu1818/switch-button)\n![bundlesize-js-image](https://img.badgesize.io/https:/unpkg.com/switch-button/dist/index.js?label=gzip\u0026compression=gzip\u0026style=flat-square)\n\nAnt Design style and reactivity switch button, it can use anywhere, no framework limit.\n\n[preview](https://zhangyu1818.github.io/switch-button/)\n\n## installation\n\n```bash\nyarn add switch-button\n```\n\n```bash\nnpm install switch-button\n```\n\n## usage\n\n```javascript\n/**\n * HTML\n *  \u003cbutton\u003e\u003c/button\u003e\n */\nimport createSwitch,{ deleteSwitch } from 'switch-button'\nimport 'switch-button/dist/index.css'\n\nconst ele = document.querySelector('button')\n\nconst switchBtn = createSwitch(ele, {\n  onChange: (checked) =\u003e {\n    console.log('checked', checked)\n  },\n})\n\n// change status will update view\nswitchBtn.checked = true\nswitchBtn.loading = true\nswitchBtn.disabled = true\n\n// delete switch button\ndeleteSwitch(ele)\n```\nthe switch button is reactivity, if you change the status value, the view will automatically change.\n\n## advanced\n\n**custom text**\n\n```javascript\nconst switchBtn = createSwitch(ele, {\n  text: ['off', 'on'],\n})\n```\n\n**default value**\n\n```javascript\nconst switchBtn = createSwitch(ele, {\n  loading:true,\n  checked:true\n})\n```\n\n**extend**\n\n```javascript\nimport { extend } from 'switch-button'\n\nconst createSwitch = extend({ \n  // all class name will start with this =\u003e 'ui-switch','ui-switch-checked' ...\n  prefixCls: 'ui',  \n  // button role\n  role: 'switch button', \n  // create small size switch button\n  small: true \n})\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyu1818%2Fswitch-button","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhangyu1818%2Fswitch-button","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyu1818%2Fswitch-button/lists"}