Skip to content

Commit e203726

Browse files
committed
Update export types
1 parent 84eab70 commit e203726

24 files changed

+3721
-278
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [22]
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set up PNPM
27+
uses: pnpm/action-setup@v4
28+
with:
29+
version: latest
30+
31+
- name: Set up Node.js v${{ matrix.node-version }}
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: ${{ matrix.node-version }}
35+
cache: pnpm
36+
37+
- name: Install dependencies
38+
run: pnpm install --frozen-lockfile
39+
40+
- name: Build tests
41+
run: pnpm build
42+
43+
- name: Run Vitest tests
44+
run: pnpm test

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/*.d.ts
2+
dist
3+
node_modules

.prettierrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "none",
4+
"bracketSameLine": true,
5+
"semi": true,
6+
"tabWidth": 4,
7+
"useTabs": false,
8+
"printWidth": 120,
9+
"overrides": [
10+
{
11+
"files": "*.ts",
12+
"options": {
13+
"parser": "typescript"
14+
}
15+
}
16+
]
17+
}

README.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,72 @@
11
# RadioBox-JS
2-
[![version](https://img.shields.io/npm/v/@carry0987/radio-box.svg)](https://www.npmjs.com/package/@carry0987/radio-box)
3-
A library for create radio type check box
2+
[![version](https://img.shields.io/npm/v/@carry0987/radio-box.svg)](https://www.npmjs.com/package/@carry0987/radio-box)
3+
![CI](https://github.com/carry0987/RadioBox-JS/actions/workflows/ci.yml/badge.svg)
4+
A library for create radio type checkbox
45

56
## Installation
67
```bash
7-
npm install @carry0987/radio-box
8+
pnpm i @carry0987/radio-box
9+
```
10+
11+
## Usage
12+
Here is a simple example to use RadioBox-JS
13+
14+
#### UMD
15+
```html
16+
<div id="app">
17+
<h1>Normal Radio Input (With label)</h1>
18+
<input type="radio" name="radio-normal" id="radio-1" value="Test-1">
19+
<label for="radio-1">Radio-1</label>
20+
<input type="radio" name="radio-normal" id="radio-2" value="Test-2" checked>
21+
<label for="radio-2">Radio-2</label>
22+
</div>
23+
<div id="app-2">
24+
<h1>Other Radio Input</h1>
25+
<input type="radio" name="radio-other" title="Radio-3" value="Test-3">
26+
<input type="radio" name="radio-other" id="radio-4" value="Test-4">
27+
<label data-radio-for="radio-4">Radio-4</label>
28+
<input type="radio" name="radio-other" value="Test-5" data-radio-id="radio-5">
29+
<label data-radio-for="radio-5">Radio-5</label>
30+
</div>
31+
<script src="dist/radioBox.min.js"></script>
32+
<script type="text/javascript">
33+
let radioBox = new radioBoxjs.RadioBox('#app input', {
34+
styles: {
35+
'.radio-box': {
36+
'margin-bottom': '5px'
37+
}
38+
},
39+
onChange: (target) => {
40+
console.log(target);
41+
}
42+
});
43+
console.log(radioBox.value);
44+
radioBox.value = 'Test-1';
45+
46+
let radioBox2 = new radioBoxjs.RadioBox('#app-2 input', {
47+
checked: 1, // You can use index or value
48+
bindLabel: false,
49+
styles: {
50+
'.radio-box': {
51+
'margin-bottom': '10px'
52+
}
53+
},
54+
onLoad: (radioBox) => {
55+
console.log(radioBox.value);
56+
}
57+
});
58+
radioBox2.onChange = (target) => {
59+
console.log(target.value);
60+
};
61+
</script>
62+
```
63+
64+
#### ES Module
65+
```ts
66+
import { RadioBox } from '@carry0987/radio-box';
67+
import '@carry0987/radio-box/theme/radioBox.min.css';
68+
69+
let radioBox = new RadioBox('#app input', {
70+
//...
71+
});
872
```

dist/radioBox.d.ts renamed to dist/index.d.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ interface OnChangeCallback {
22
(target: HTMLInputElement): void;
33
}
44
interface OnLoadCallback {
5-
(radioBox: any): void;
5+
(radioBox: RadioBox): void;
66
}
77
interface RadioBoxOption {
88
checked: string | number | null;
@@ -28,6 +28,23 @@ interface RadioInputElement extends HTMLInputElement {
2828
labelToRestore?: HTMLLabelElement;
2929
}
3030

31+
type interfaces_OnChangeCallback = OnChangeCallback;
32+
type interfaces_OnLoadCallback = OnLoadCallback;
33+
type interfaces_RadioBoxOption = RadioBoxOption;
34+
type interfaces_RadioInputElement = RadioInputElement;
35+
type interfaces_RadioboxTemplate = RadioboxTemplate;
36+
type interfaces_RadioboxTitleDetail = RadioboxTitleDetail;
37+
declare namespace interfaces {
38+
export type { interfaces_OnChangeCallback as OnChangeCallback, interfaces_OnLoadCallback as OnLoadCallback, interfaces_RadioBoxOption as RadioBoxOption, interfaces_RadioInputElement as RadioInputElement, interfaces_RadioboxTemplate as RadioboxTemplate, interfaces_RadioboxTitleDetail as RadioboxTitleDetail };
39+
}
40+
41+
type InputElement = string | HTMLInputElement | Array<HTMLInputElement> | NodeListOf<HTMLInputElement> | null;
42+
43+
type types_InputElement = InputElement;
44+
declare namespace types {
45+
export type { types_InputElement as InputElement };
46+
}
47+
3148
declare class RadioBox {
3249
private static instances;
3350
private static version;
@@ -39,7 +56,7 @@ declare class RadioBox {
3956
private groupName;
4057
private onChangeCallback?;
4158
private onLoadCallback?;
42-
constructor(element: string | HTMLInputElement, option: Partial<RadioBoxOption>);
59+
constructor(element: InputElement, option: Partial<RadioBoxOption>);
4360
private init;
4461
private injectStyles;
4562
private setupCallbacks;
@@ -71,4 +88,4 @@ declare class RadioBox {
7188
static destroyAll(): void;
7289
}
7390

74-
export { type OnChangeCallback, type OnLoadCallback, type RadioBoxOption, type RadioInputElement, type RadioboxTemplate, type RadioboxTitleDetail, RadioBox as default };
91+
export { RadioBox, interfaces as RadioBoxInterface, types as RadioBoxType };

0 commit comments

Comments
 (0)