@get-set/gs-select
v1.0.25
Published
Get-Set Select
Readme
GSSelect Package
This repository builds two outputs:
- Vanilla JS bundle (
dist/bundle.js) — for direct browser usage (e.g.<script src="dist/bundle.js"></script>or CommonJS require). - React component (
dist/components/GSSelect.js) — aGSSelectReact component you can import in React projects.
Building
Run all builds:
npm install # initial setup
npm run build # builds both JS and React outputsIndividual targets:
npm run build:js– webpack bundle for non‑React usagenpm run build:react– compile React component withtsc
The React build writes compiled .js, .js.map, and .d.ts into dist/components.
Publishing to npm
- Bump the version in
package.json. - Make sure the build artifacts are up to date:
npm run build - Verify
distanddist-jsare included (thefilesfield in package.json ensures they are). npm publishfrom project root.
The published package exposes the two entrypoints via the exports map:
import GSSelect from 'gsselect';— gives the React componentconst GSSelect = require('gsselect');— gives the plain JS constructor
The main/module/types fields also point at the React build, which is standard for a component package.
Using the React component
The component now accepts a regular React ref. When you pass a ref it will point at the underlying <select> element, allowing you to call DOM methods or inspect the element from a parent.
import React, { useRef, useEffect } from 'react';
import GSSelect from 'gsselect';
function App() {
const selectEl = useRef<HTMLSelectElement | null>(null);
useEffect(() => {
if (selectEl.current) {
// you can interact with the DOM node directly
console.log('select node', selectEl.current);
}
}, []);
return (
<GSSelect
ref={selectEl}
closeAfterSelect={false}
icon="⇩⟴"
onChange={(ref) => console.log('ready', ref)}
>
<option value="1">One</option>
<option value="2">Two</option>
</GSSelect>
);
}The rest of the API remains unchanged.
Using the plain JS bundle
<script src="https://unpkg.com/gsselect/dist-js/bundle.js"></script>
<script>
new GSSelect('.select1');
</script>Both builds are packaged together so you maintain one npm package for both flavors.
