{"id":13341648,"url":"https://github.com/rwieruch/web-components-dropdown","last_synced_at":"2025-04-15T17:33:48.575Z","repository":{"id":57915843,"uuid":"190154002","full_name":"rwieruch/web-components-dropdown","owner":"rwieruch","description":"Dropdown built as Web Componment.","archived":false,"fork":false,"pushed_at":"2020-05-08T15:49:29.000Z","size":691,"stargazers_count":22,"open_issues_count":4,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-05T11:16:13.099Z","etag":null,"topics":["dropdown","web-component","web-components"],"latest_commit_sha":null,"homepage":"https://www.robinwieruch.de","language":"JavaScript","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/rwieruch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-04T07:44:10.000Z","updated_at":"2023-01-29T14:44:55.000Z","dependencies_parsed_at":"2022-08-26T15:42:24.493Z","dependency_job_id":null,"html_url":"https://github.com/rwieruch/web-components-dropdown","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwieruch%2Fweb-components-dropdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwieruch%2Fweb-components-dropdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwieruch%2Fweb-components-dropdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwieruch%2Fweb-components-dropdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwieruch","download_url":"https://codeload.github.com/rwieruch/web-components-dropdown/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219883329,"owners_count":16563259,"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":["dropdown","web-component","web-components"],"created_at":"2024-07-29T19:25:39.560Z","updated_at":"2024-10-16T20:21:54.154Z","avatar_url":"https://github.com/rwieruch.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dropdown with Web Components\n\n[![Build Status](https://travis-ci.org/rwieruch/web-components-dropdown.svg?branch=master)](https://travis-ci.org/rwieruch/web-components-dropdown) [![Slack](https://slack-the-road-to-learn-react.wieruch.com/badge.svg)](https://slack-the-road-to-learn-react.wieruch.com/) [![Greenkeeper badge](https://badges.greenkeeper.io/rwieruch/web-components-dropdown.svg)](https://greenkeeper.io/)\n\nDropdown as Web Componment.\n\n* [Learn how to build Web Components.](https://www.robinwieruch.de/web-components-tutorial)\n* [Learn how to use Web Components in React.](https://www.robinwieruch.de/react-web-components)\n\n## How to use:\n\nInstall: `npm install road-dropdown`\n\n### Vanilla JS + HTML\n\nUsage with attributes only except for function:\n\n```\n// HTML\n\n\u003croad-dropdown\n  label=\"Dropdown\"\n  option=\"option2\"\n  options='{ \"option1\": { \"label\": \"Option 1\" }, \"option2\": { \"label\": \"Option 2\" } }'\n\u003e\u003c/road-dropdown\u003e\n```\n\n```\n// JavaScript\n\ndocument\n  .querySelector('road-dropdown')\n  .addEventListener('onChange', value =\u003e console.log(value));\n```\n\nAlternative with properties for object/array:\n\n```\n// HTML\n\n\u003croad-dropdown\n  label=\"Dropdown\"\n  option=\"option2\"\n\u003e\u003c/road-dropdown\u003e\n```\n\n```\n// JavaScript\n\ndocument.querySelector('road-dropdown').options = {\n  option1: { label: 'Option 1' },\n  option2: { label: 'Option 2' },\n};\n\ndocument\n  .querySelector('road-dropdown')\n  .addEventListener('onChange', value =\u003e console.log(value));\n```\n\n### React\n\n```\nimport React from 'react';\n\n// npm install road-dropdown\nimport 'road-dropdown';\n\nconst Dropdown = ({ label, option, options, onChange }) =\u003e {\n  const ref = React.createRef();\n\n  React.useLayoutEffect(() =\u003e {\n    const handleChange = customEvent =\u003e onChange(customEvent.detail);\n\n    ref.current.addEventListener('onChange', handleChange);\n\n    return () =\u003e ref.current.removeEventListener('onChange', handleChange);\n  }, []);\n\n  return (\n    \u003croad-dropdown\n      ref={ref}\n      label={label}\n      option={option}\n      options={JSON.stringify(options)}\n      onChange={onChange}\n    /\u003e\n  );\n};\n\nexport default Dropdown;\n```\n\n### React with Hook\n\nHook to use Web Components in React Components: [use-custom-element](https://github.com/the-road-to-learn-react/use-custom-element).\n\n```\nimport React from 'react';\n\n// npm install road-dropdown\nimport 'road-dropdown';\n\n// npm install use-custom-element\nimport useCustomElement from 'use-custom-element';\n\nconst Dropdown = props =\u003e {\n  const [customElementProps, ref] = useCustomElement(props);\n\n  return \u003croad-dropdown {...customElementProps} ref={ref} /\u003e;\n};\n```\n\n## Contribution\n\n* `git clone git@github.com:rwieruch/web-components-dropdown.git`\n* cd web-components-dropdown\n* npm install\n* npm start\n* visit `http://localhost:8080`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwieruch%2Fweb-components-dropdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwieruch%2Fweb-components-dropdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwieruch%2Fweb-components-dropdown/lists"}