react-select-media-devices-modal 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # react-select-media-devices-modal
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/react-select-media-devices-modal.svg)](https://badge.fury.io/js/react-select-media-devices-modal)
4
+ [![Test](https://github.com/kadoshita/react-select-media-devices-modal/actions/workflows/test.yaml/badge.svg?branch=master)](https://github.com/kadoshita/react-select-media-devices-modal/actions/workflows/test.yaml)
5
+ [![E2E Test](https://github.com/kadoshita/react-select-media-devices-modal/actions/workflows/e2e-test.yaml/badge.svg)](https://github.com/kadoshita/react-select-media-devices-modal/actions/workflows/e2e-test.yaml)
4
6
  [![Release](https://github.com/kadoshita/react-select-media-devices-modal/actions/workflows/release.yaml/badge.svg)](https://github.com/kadoshita/react-select-media-devices-modal/actions/workflows/release.yaml)
7
+ [![Deploy to GitHub Pages](https://github.com/kadoshita/react-select-media-devices-modal/actions/workflows/deploy.yaml/badge.svg?branch=master)](https://github.com/kadoshita/react-select-media-devices-modal/actions/workflows/deploy.yaml)
5
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
9
 
7
10
  A React component library for select media devices.
@@ -22,7 +25,7 @@ npm install --save react-select-media-devices-modal
22
25
 
23
26
  ## Usage
24
27
 
25
- ```tsx
28
+ ```jsx
26
29
  import { useState } from 'react';
27
30
  import { SelectMediaDevicesModal } from 'react-select-media-devices-modal';
28
31
 
@@ -49,8 +52,8 @@ function App() {
49
52
  audioInputDeviceLabel="Audio input device"
50
53
  audioOutputDeviceLabel="Audio output device"
51
54
  videoInputDeviceLabel="Video input device"
52
- ConfirmButtonText="Confirm"
53
- CancelButtonText="Cancel"
55
+ confirmButtonText="Confirm"
56
+ cancelButtonText="Cancel"
54
57
  allowOutsideClick={false}
55
58
  onDeviceSelected={handleDeviceSelected}
56
59
  onDeviceSelectCanceled={handleDeviceSelectCanceled}
@@ -75,8 +78,8 @@ export default App;
75
78
  | audioInputDeviceLabel | `string` | `'audio input device'` | Label for list of audio input devices. |
76
79
  | audioOutputDeviceLabel | `string` | `'audio output device'` | Label for list of audio output devices. |
77
80
  | videoInputDeviceLabel | `string` | `'video input device'` | Label for list of video input devices. |
78
- | ConfirmButtonText | `string` | `'Confirm'` | Label for the confirm button. |
79
- | CancelButtonText | `string` | `'Cancel'` | Label for the cancel button. |
81
+ | confirmButtonText | `string` | `'Confirm'` | Label for the confirm button. |
82
+ | cancelButtonText | `string` | `'Cancel'` | Label for the cancel button. |
80
83
  | allowOutsideClick | `boolean` | `true` | Flag that cancel selection when clicking outside of the modal. |
81
84
  | onDeviceSelected | `function` | `(devices: { audioInput?: MediaDeviceInfo; audioOutput?: MediaDeviceInfo; videoInput?: MediaDeviceInfo; }) => void` | Handler function called when devices are selected. |
82
85
  | onDeviceSelectCanceled | `function` | `() => void` | Handler function called when selection canceled. |
@@ -1,94 +1,99 @@
1
- import e, { useState as l, useEffect as w } from "react";
2
- const G = "_background_a8nxk_1", P = "_modal_a8nxk_13", R = "_deviceLists_a8nxk_19", S = "_buttons_a8nxk_23", T = "_chancelButton_a8nxk_30", U = "_confirmButton_a8nxk_32", o = {
3
- background: G,
4
- modal: P,
5
- deviceLists: R,
6
- buttons: S,
7
- chancelButton: T,
8
- confirmButton: U
9
- }, q = () => {
1
+ import e, { useState as l, useEffect as j } from "react";
2
+ const x = "_background_2h4vl_1", G = "_modal_2h4vl_13", P = "_deviceLists_2h4vl_19", R = "_buttons_2h4vl_23", S = "_chancelButton_2h4vl_30", T = "_confirmButton_2h4vl_32", a = {
3
+ background: x,
4
+ modal: G,
5
+ deviceLists: P,
6
+ buttons: R,
7
+ chancelButton: S,
8
+ confirmButton: T
9
+ }, U = () => {
10
10
  const [n, c] = l([]);
11
11
  return [n, () => {
12
12
  (async () => {
13
- const s = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 }), i = await navigator.mediaDevices.enumerateDevices();
14
- c(i), s.getTracks().forEach((u) => u.stop());
13
+ const u = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 }), s = await navigator.mediaDevices.enumerateDevices();
14
+ c(s), u.getTracks().forEach((i) => i.stop());
15
15
  })();
16
16
  }];
17
- }, z = ({ name: n, value: c }) => /* @__PURE__ */ e.createElement("option", { value: c }, n), g = ({ devices: n, label: c, onChange: a }) => {
17
+ }, z = ({ name: n, value: c }) => /* @__PURE__ */ e.createElement("option", { value: c }, n), H = "_deviceList_1bfq1_1", J = "_select_1bfq1_5", C = {
18
+ deviceList: H,
19
+ select: J
20
+ }, h = ({ devices: n, label: c, onChange: o }) => {
18
21
  if (n === void 0)
19
22
  return /* @__PURE__ */ e.createElement(e.Fragment, null);
20
- const s = (i) => {
21
- a(i.target.value);
22
- };
23
- return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("label", { htmlFor: "device-select" }, c), /* @__PURE__ */ e.createElement("select", { name: "device-select", onChange: s }, n.map((i, u) => /* @__PURE__ */ e.createElement(z, { value: i.deviceId, name: i.label, key: u }))));
24
- }, _ = ({ className: n, children: c, onClick: a }) => /* @__PURE__ */ e.createElement("button", { onClick: a, className: [n].filter(Boolean).join(" ") }, c), J = ({
23
+ const u = (i) => {
24
+ o(i.target.value);
25
+ }, s = `device-select-${c.toLowerCase().replace(/\s/g, "-")}`;
26
+ return /* @__PURE__ */ e.createElement("div", { className: C.deviceList }, /* @__PURE__ */ e.createElement("label", { htmlFor: s }, c), /* @__PURE__ */ e.createElement("select", { className: C.select, id: s, onChange: u }, n.map((i, v) => /* @__PURE__ */ e.createElement(z, { value: i.deviceId, name: i.label, key: v }))));
27
+ }, K = "_button_keu24_1", Q = {
28
+ button: K
29
+ }, k = ({ className: n, children: c, onClick: o }) => /* @__PURE__ */ e.createElement("button", { onClick: o, className: [Q.button, n].filter(Boolean).join(" ") }, c), X = ({
25
30
  isSelectAudioInput: n = !0,
26
31
  isSelectAudioOutput: c = !0,
27
- isSelectVideoInput: a = !0,
28
- open: s,
29
- audioInputDeviceLabel: i = "audio input device",
30
- audioOutputDeviceLabel: u = "audio output device",
31
- videoInputDeviceLabel: C = "video input device",
32
- ConfirmButtonText: I = "Confirm",
33
- CancelButtonText: b = "Cancel",
34
- allowOutsideClick: D = !0,
32
+ isSelectVideoInput: o = !0,
33
+ open: u,
34
+ audioInputDeviceLabel: s = "audio input device",
35
+ audioOutputDeviceLabel: i = "audio output device",
36
+ videoInputDeviceLabel: v = "video input device",
37
+ confirmButtonText: I = "Confirm",
38
+ cancelButtonText: L = "Cancel",
39
+ allowOutsideClick: g = !0,
35
40
  onDeviceSelected: B,
36
- onDeviceSelectCanceled: k
41
+ onDeviceSelectCanceled: D
37
42
  }) => {
38
- const [r, x] = q(), [h, N] = l(), [E, L] = l(), [f, O] = l(), v = r.filter((t) => t.kind === "audioinput"), m = r.filter((t) => t.kind === "audiooutput"), p = r.filter((t) => t.kind === "videoinput");
39
- w(() => {
40
- x();
43
+ const [r, N] = U(), [f, O] = l(), [b, A] = l(), [E, F] = l(), m = r.filter((t) => t.kind === "audioinput"), p = r.filter((t) => t.kind === "audiooutput"), _ = r.filter((t) => t.kind === "videoinput");
44
+ j(() => {
45
+ N();
41
46
  }, []);
42
- const A = () => {
47
+ const M = () => {
43
48
  B({
44
- audioInput: h !== void 0 ? h : v[0],
45
- audioOutput: E !== void 0 ? E : m[0],
46
- videoInput: f !== void 0 ? f : p[0]
49
+ audioInput: f !== void 0 ? f : m[0],
50
+ audioOutput: b !== void 0 ? b : p[0],
51
+ videoInput: E !== void 0 ? E : _[0]
47
52
  });
48
- }, F = () => {
49
- k();
50
- }, M = (t) => {
51
- N(v.find((d) => d.deviceId === t));
53
+ }, $ = () => {
54
+ D();
55
+ }, q = (t) => {
56
+ O(m.find((d) => d.deviceId === t));
57
+ }, w = (t) => {
58
+ A(p.find((d) => d.deviceId === t));
52
59
  }, y = (t) => {
53
- L(m.find((d) => d.deviceId === t));
54
- }, V = (t) => {
55
- O(p.find((d) => d.deviceId === t));
56
- }, j = () => {
57
- k();
60
+ F(_.find((d) => d.deviceId === t));
61
+ }, V = () => {
62
+ D();
58
63
  };
59
- return s ? /* @__PURE__ */ e.createElement("div", { className: o.background, ...D ? { onClick: j } : {} }, /* @__PURE__ */ e.createElement(
64
+ return u ? /* @__PURE__ */ e.createElement("div", { className: a.background, ...g ? { onClick: V } : {} }, /* @__PURE__ */ e.createElement(
60
65
  "div",
61
66
  {
62
- className: o.modal,
63
- ...D ? {
67
+ className: a.modal,
68
+ ...g ? {
64
69
  onClick: (t) => t.stopPropagation()
65
70
  } : {}
66
71
  },
67
- /* @__PURE__ */ e.createElement("div", { className: o.deviceLists }, n && /* @__PURE__ */ e.createElement(
68
- g,
72
+ /* @__PURE__ */ e.createElement("div", { className: a.deviceLists }, n && /* @__PURE__ */ e.createElement(
73
+ h,
69
74
  {
70
- label: i,
71
- devices: v,
72
- onChange: M
75
+ label: s,
76
+ devices: m,
77
+ onChange: q
73
78
  }
74
79
  ), c && /* @__PURE__ */ e.createElement(
75
- g,
80
+ h,
76
81
  {
77
- label: u,
78
- devices: m,
79
- onChange: y
82
+ label: i,
83
+ devices: p,
84
+ onChange: w
80
85
  }
81
- ), a && /* @__PURE__ */ e.createElement(
82
- g,
86
+ ), o && /* @__PURE__ */ e.createElement(
87
+ h,
83
88
  {
84
- label: C,
85
- devices: p,
86
- onChange: V
89
+ label: v,
90
+ devices: _,
91
+ onChange: y
87
92
  }
88
93
  )),
89
- /* @__PURE__ */ e.createElement("div", { className: o.buttons }, /* @__PURE__ */ e.createElement(_, { className: o.cancelButton, onClick: F }, b), /* @__PURE__ */ e.createElement(_, { className: o.confirmButton, onClick: A }, I))
94
+ /* @__PURE__ */ e.createElement("div", { className: a.buttons }, /* @__PURE__ */ e.createElement(k, { className: a.cancelButton, onClick: $ }, L), /* @__PURE__ */ e.createElement(k, { className: a.confirmButton, onClick: M }, I))
90
95
  )) : /* @__PURE__ */ e.createElement(e.Fragment, null);
91
96
  };
92
97
  export {
93
- J as SelectMediaDevicesModal
98
+ X as SelectMediaDevicesModal
94
99
  };
@@ -1 +1 @@
1
- (function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.ReactSelectMediaDevicesModal={},c.React))})(this,function(c,e){"use strict";const s={background:"_background_a8nxk_1",modal:"_modal_a8nxk_13",deviceLists:"_deviceLists_a8nxk_19",buttons:"_buttons_a8nxk_23",chancelButton:"_chancelButton_a8nxk_30",confirmButton:"_confirmButton_a8nxk_32"},_=()=>{const[n,i]=e.useState([]);return[n,()=>{(async()=>{const u=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0}),o=await navigator.mediaDevices.enumerateDevices();i(o),u.getTracks().forEach(d=>d.stop())})()}]},C=({name:n,value:i})=>e.createElement("option",{value:i},n),r=({devices:n,label:i,onChange:a})=>{if(n===void 0)return e.createElement(e.Fragment,null);const u=o=>{a(o.target.value)};return e.createElement(e.Fragment,null,e.createElement("label",{htmlFor:"device-select"},i),e.createElement("select",{name:"device-select",onChange:u},n.map((o,d)=>e.createElement(C,{value:o.deviceId,name:o.label,key:d}))))},g=({className:n,children:i,onClick:a})=>e.createElement("button",{onClick:a,className:[n].filter(Boolean).join(" ")},i),I=({isSelectAudioInput:n=!0,isSelectAudioOutput:i=!0,isSelectVideoInput:a=!0,open:u,audioInputDeviceLabel:o="audio input device",audioOutputDeviceLabel:d="audio output device",videoInputDeviceLabel:B="video input device",ConfirmButtonText:x="Confirm",CancelButtonText:M="Cancel",allowOutsideClick:h=!0,onDeviceSelected:S,onDeviceSelectCanceled:D})=>{const[v,L]=_(),[k,N]=e.useState(),[E,y]=e.useState(),[b,O]=e.useState(),m=v.filter(t=>t.kind==="audioinput"),p=v.filter(t=>t.kind==="audiooutput"),f=v.filter(t=>t.kind==="videoinput");e.useEffect(()=>{L()},[]);const A=()=>{S({audioInput:k!==void 0?k:m[0],audioOutput:E!==void 0?E:p[0],videoInput:b!==void 0?b:f[0]})},F=()=>{D()},T=t=>{N(m.find(l=>l.deviceId===t))},j=t=>{y(p.find(l=>l.deviceId===t))},P=t=>{O(f.find(l=>l.deviceId===t))},V=()=>{D()};return u?e.createElement("div",{className:s.background,...h?{onClick:V}:{}},e.createElement("div",{className:s.modal,...h?{onClick:t=>t.stopPropagation()}:{}},e.createElement("div",{className:s.deviceLists},n&&e.createElement(r,{label:o,devices:m,onChange:T}),i&&e.createElement(r,{label:d,devices:p,onChange:j}),a&&e.createElement(r,{label:B,devices:f,onChange:P})),e.createElement("div",{className:s.buttons},e.createElement(g,{className:s.cancelButton,onClick:F},M),e.createElement(g,{className:s.confirmButton,onClick:A},x)))):e.createElement(e.Fragment,null)};c.SelectMediaDevicesModal=I,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.ReactSelectMediaDevicesModal={},c.React))})(this,function(c,e){"use strict";const s={background:"_background_2h4vl_1",modal:"_modal_2h4vl_13",deviceLists:"_deviceLists_2h4vl_19",buttons:"_buttons_2h4vl_23",chancelButton:"_chancelButton_2h4vl_30",confirmButton:"_confirmButton_2h4vl_32"},I=()=>{const[n,i]=e.useState([]);return[n,()=>{(async()=>{const a=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0}),d=await navigator.mediaDevices.enumerateDevices();i(d),a.getTracks().forEach(o=>o.stop())})()}]},L=({name:n,value:i})=>e.createElement("option",{value:i},n),_={deviceList:"_deviceList_1bfq1_1",select:"_select_1bfq1_5"},r=({devices:n,label:i,onChange:u})=>{if(n===void 0)return e.createElement(e.Fragment,null);const a=o=>{u(o.target.value)},d=`device-select-${i.toLowerCase().replace(/\s/g,"-")}`;return e.createElement("div",{className:_.deviceList},e.createElement("label",{htmlFor:d},i),e.createElement("select",{className:_.select,id:d,onChange:a},n.map((o,v)=>e.createElement(L,{value:o.deviceId,name:o.label,key:v}))))},B={button:"_button_keu24_1"},g=({className:n,children:i,onClick:u})=>e.createElement("button",{onClick:u,className:[B.button,n].filter(Boolean).join(" ")},i),N=({isSelectAudioInput:n=!0,isSelectAudioOutput:i=!0,isSelectVideoInput:u=!0,open:a,audioInputDeviceLabel:d="audio input device",audioOutputDeviceLabel:o="audio output device",videoInputDeviceLabel:v="video input device",confirmButtonText:M="Confirm",cancelButtonText:S="Cancel",allowOutsideClick:b=!0,onDeviceSelected:y,onDeviceSelectCanceled:D})=>{const[m,O]=I(),[E,A]=e.useState(),[C,T]=e.useState(),[k,j]=e.useState(),p=m.filter(t=>t.kind==="audioinput"),f=m.filter(t=>t.kind==="audiooutput"),h=m.filter(t=>t.kind==="videoinput");e.useEffect(()=>{O()},[]);const q=()=>{y({audioInput:E!==void 0?E:p[0],audioOutput:C!==void 0?C:f[0],videoInput:k!==void 0?k:h[0]})},F=()=>{D()},$=t=>{A(p.find(l=>l.deviceId===t))},w=t=>{T(f.find(l=>l.deviceId===t))},x=t=>{j(h.find(l=>l.deviceId===t))},P=()=>{D()};return a?e.createElement("div",{className:s.background,...b?{onClick:P}:{}},e.createElement("div",{className:s.modal,...b?{onClick:t=>t.stopPropagation()}:{}},e.createElement("div",{className:s.deviceLists},n&&e.createElement(r,{label:d,devices:p,onChange:$}),i&&e.createElement(r,{label:o,devices:f,onChange:w}),u&&e.createElement(r,{label:v,devices:h,onChange:x})),e.createElement("div",{className:s.buttons},e.createElement(g,{className:s.cancelButton,onClick:F},S),e.createElement(g,{className:s.confirmButton,onClick:q},M)))):e.createElement(e.Fragment,null)};c.SelectMediaDevicesModal=N,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- ._background_a8nxk_1{position:fixed;top:0;left:0;width:100%;height:100%;background-color:#0000004d;display:flex;align-items:center;justify-content:center}._modal_a8nxk_13{background:white;padding:16px;border-radius:8px}._deviceLists_a8nxk_19{display:grid}._buttons_a8nxk_23{padding-top:8px;display:flex;align-items:center;justify-content:right}._confirmButton_a8nxk_32{margin-left:4px}
1
+ ._background_2h4vl_1{position:fixed;top:0;left:0;width:100%;height:100%;background-color:#0000004d;display:flex;align-items:center;justify-content:center}._modal_2h4vl_13{background:white;padding:16px;border-radius:8px}._deviceLists_2h4vl_19{display:grid}._buttons_2h4vl_23{padding-top:16px;display:flex;align-items:center;justify-content:right}._confirmButton_2h4vl_32{margin-left:4px}._deviceList_1bfq1_1{padding-top:8px}._select_1bfq1_5{margin-top:4px;border-radius:4px;height:32px;display:flex;align-items:center;justify-content:right;width:100%}._button_keu24_1{border-radius:4px;height:32px;padding-left:16px;padding-right:16px;background-color:#fff;border-width:1px}
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  interface ButtonProps {
3
- className: string;
3
+ className?: string;
4
4
  children: ReactNode;
5
5
  onClick: () => void;
6
6
  }
@@ -7,8 +7,8 @@ interface SelectMediaDevicesModalProps {
7
7
  audioInputDeviceLabel: string;
8
8
  audioOutputDeviceLabel: string;
9
9
  videoInputDeviceLabel: string;
10
- ConfirmButtonText: string;
11
- CancelButtonText: string;
10
+ confirmButtonText: string;
11
+ cancelButtonText: string;
12
12
  allowOutsideClick: boolean;
13
13
  onDeviceSelected: (devices: {
14
14
  audioInput?: MediaDeviceInfo;
@@ -17,5 +17,5 @@ interface SelectMediaDevicesModalProps {
17
17
  }) => void;
18
18
  onDeviceSelectCanceled: () => void;
19
19
  }
20
- declare const SelectMediaDevicesModal: ({ isSelectAudioInput, isSelectAudioOutput, isSelectVideoInput, open, audioInputDeviceLabel, audioOutputDeviceLabel, videoInputDeviceLabel, ConfirmButtonText, CancelButtonText, allowOutsideClick, onDeviceSelected, onDeviceSelectCanceled, }: SelectMediaDevicesModalProps) => JSX.Element;
20
+ declare const SelectMediaDevicesModal: ({ isSelectAudioInput, isSelectAudioOutput, isSelectVideoInput, open, audioInputDeviceLabel, audioOutputDeviceLabel, videoInputDeviceLabel, confirmButtonText, cancelButtonText, allowOutsideClick, onDeviceSelected, onDeviceSelectCanceled, }: SelectMediaDevicesModalProps) => JSX.Element;
21
21
  export default SelectMediaDevicesModal;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-select-media-devices-modal",
3
3
  "description": "A React component library for select media devices",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,7 +32,10 @@
32
32
  ],
33
33
  "scripts": {
34
34
  "dev": "vite serve example",
35
- "build": "vite build"
35
+ "build": "vite build",
36
+ "test": "vitest",
37
+ "coverage": "vitest run --coverage",
38
+ "test:e2e": "vitest run -c vitest.e2e.config.ts"
36
39
  },
37
40
  "dependencies": {
38
41
  "react": "^18.2.0",
@@ -41,14 +44,23 @@
41
44
  },
42
45
  "devDependencies": {
43
46
  "@mdx-js/react": "^2.3.0",
47
+ "@playwright/test": "^1.33.0",
44
48
  "@rollup/plugin-typescript": "^11.1.0",
49
+ "@testing-library/jest-dom": "^5.16.5",
50
+ "@testing-library/react": "^14.0.0",
51
+ "@testing-library/user-event": "^14.4.3",
45
52
  "@types/node": "^18.15.11",
46
53
  "@types/react": "^18.0.33",
47
54
  "@vitejs/plugin-react": "^3.1.0",
55
+ "@vitest/coverage-c8": "^0.30.1",
56
+ "@vitest/ui": "^0.30.1",
57
+ "jsdom": "^21.1.1",
58
+ "playwright": "^1.33.0",
48
59
  "rimraf": "^4.4.1",
49
60
  "serve": "^14.2.0",
50
61
  "vite": "^4.2.1",
51
62
  "vite-pages-theme-doc": "^4.0.0",
52
- "vite-plugin-react-pages": "^4.0.0"
63
+ "vite-plugin-react-pages": "^4.0.0",
64
+ "vitest": "^0.30.1"
53
65
  }
54
66
  }