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

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
@@ -49,8 +49,8 @@ function App() {
49
49
  audioInputDeviceLabel="Audio input device"
50
50
  audioOutputDeviceLabel="Audio output device"
51
51
  videoInputDeviceLabel="Video input device"
52
- ConfirmButtonText="Confirm"
53
- CancelButtonText="Cancel"
52
+ confirmButtonText="Confirm"
53
+ cancelButtonText="Cancel"
54
54
  allowOutsideClick={false}
55
55
  onDeviceSelected={handleDeviceSelected}
56
56
  onDeviceSelectCanceled={handleDeviceSelectCanceled}
@@ -75,8 +75,8 @@ export default App;
75
75
  | audioInputDeviceLabel | `string` | `'audio input device'` | Label for list of audio input devices. |
76
76
  | audioOutputDeviceLabel | `string` | `'audio output device'` | Label for list of audio output devices. |
77
77
  | 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. |
78
+ | confirmButtonText | `string` | `'Confirm'` | Label for the confirm button. |
79
+ | cancelButtonText | `string` | `'Cancel'` | Label for the cancel button. |
80
80
  | allowOutsideClick | `boolean` | `true` | Flag that cancel selection when clicking outside of the modal. |
81
81
  | onDeviceSelected | `function` | `(devices: { audioInput?: MediaDeviceInfo; audioOutput?: MediaDeviceInfo; videoInput?: MediaDeviceInfo; }) => void` | Handler function called when devices are selected. |
82
82
  | onDeviceSelectCanceled | `function` | `() => void` | Handler function called when selection canceled. |
@@ -1,94 +1,94 @@
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 = {
1
+ import e, { useState as l, useEffect as j } 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", s = {
3
3
  background: G,
4
4
  modal: P,
5
5
  deviceLists: R,
6
6
  buttons: S,
7
7
  chancelButton: T,
8
8
  confirmButton: U
9
- }, q = () => {
9
+ }, $ = () => {
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 }), a = await navigator.mediaDevices.enumerateDevices();
14
+ c(a), 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
+ }, q = ({ name: n, value: c }) => /* @__PURE__ */ e.createElement("option", { value: c }, n), D = ({ devices: n, label: c, onChange: o }) => {
18
18
  if (n === void 0)
19
19
  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 = ({
20
+ const u = (i) => {
21
+ o(i.target.value);
22
+ }, a = `device-select-${c.toLowerCase().replace(/\s/g, "-")}`;
23
+ return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("label", { htmlFor: a }, c), /* @__PURE__ */ e.createElement("select", { id: a, onChange: u }, n.map((i, r) => /* @__PURE__ */ e.createElement(q, { value: i.deviceId, name: i.label, key: r }))));
24
+ }, _ = ({ className: n, children: c, onClick: o }) => /* @__PURE__ */ e.createElement("button", { onClick: o, className: [n].filter(Boolean).join(" ") }, c), H = ({
25
25
  isSelectAudioInput: n = !0,
26
26
  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,
27
+ isSelectVideoInput: o = !0,
28
+ open: u,
29
+ audioInputDeviceLabel: a = "audio input device",
30
+ audioOutputDeviceLabel: i = "audio output device",
31
+ videoInputDeviceLabel: r = "video input device",
32
+ confirmButtonText: I = "Confirm",
33
+ cancelButtonText: b = "Cancel",
34
+ allowOutsideClick: k = !0,
35
35
  onDeviceSelected: B,
36
- onDeviceSelectCanceled: k
36
+ onDeviceSelectCanceled: h
37
37
  }) => {
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(() => {
38
+ const [v, x] = $(), [E, L] = l(), [f, N] = l(), [C, O] = l(), m = v.filter((t) => t.kind === "audioinput"), p = v.filter((t) => t.kind === "audiooutput"), g = v.filter((t) => t.kind === "videoinput");
39
+ j(() => {
40
40
  x();
41
41
  }, []);
42
42
  const A = () => {
43
43
  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]
44
+ audioInput: E !== void 0 ? E : m[0],
45
+ audioOutput: f !== void 0 ? f : p[0],
46
+ videoInput: C !== void 0 ? C : g[0]
47
47
  });
48
48
  }, F = () => {
49
- k();
49
+ h();
50
50
  }, M = (t) => {
51
- N(v.find((d) => d.deviceId === t));
52
- }, y = (t) => {
53
51
  L(m.find((d) => d.deviceId === t));
54
- }, V = (t) => {
55
- O(p.find((d) => d.deviceId === t));
56
- }, j = () => {
57
- k();
52
+ }, w = (t) => {
53
+ N(p.find((d) => d.deviceId === t));
54
+ }, y = (t) => {
55
+ O(g.find((d) => d.deviceId === t));
56
+ }, V = () => {
57
+ h();
58
58
  };
59
- return s ? /* @__PURE__ */ e.createElement("div", { className: o.background, ...D ? { onClick: j } : {} }, /* @__PURE__ */ e.createElement(
59
+ return u ? /* @__PURE__ */ e.createElement("div", { className: s.background, ...k ? { onClick: V } : {} }, /* @__PURE__ */ e.createElement(
60
60
  "div",
61
61
  {
62
- className: o.modal,
63
- ...D ? {
62
+ className: s.modal,
63
+ ...k ? {
64
64
  onClick: (t) => t.stopPropagation()
65
65
  } : {}
66
66
  },
67
- /* @__PURE__ */ e.createElement("div", { className: o.deviceLists }, n && /* @__PURE__ */ e.createElement(
68
- g,
67
+ /* @__PURE__ */ e.createElement("div", { className: s.deviceLists }, n && /* @__PURE__ */ e.createElement(
68
+ D,
69
69
  {
70
- label: i,
71
- devices: v,
70
+ label: a,
71
+ devices: m,
72
72
  onChange: M
73
73
  }
74
74
  ), c && /* @__PURE__ */ e.createElement(
75
- g,
75
+ D,
76
76
  {
77
- label: u,
78
- devices: m,
79
- onChange: y
77
+ label: i,
78
+ devices: p,
79
+ onChange: w
80
80
  }
81
- ), a && /* @__PURE__ */ e.createElement(
82
- g,
81
+ ), o && /* @__PURE__ */ e.createElement(
82
+ D,
83
83
  {
84
- label: C,
85
- devices: p,
86
- onChange: V
84
+ label: r,
85
+ devices: g,
86
+ onChange: y
87
87
  }
88
88
  )),
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))
89
+ /* @__PURE__ */ e.createElement("div", { className: s.buttons }, /* @__PURE__ */ e.createElement(_, { className: s.cancelButton, onClick: F }, b), /* @__PURE__ */ e.createElement(_, { className: s.confirmButton, onClick: A }, I))
90
90
  )) : /* @__PURE__ */ e.createElement(e.Fragment, null);
91
91
  };
92
92
  export {
93
- J as SelectMediaDevicesModal
93
+ H as SelectMediaDevicesModal
94
94
  };
@@ -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_a8nxk_1",modal:"_modal_a8nxk_13",deviceLists:"_deviceLists_a8nxk_19",buttons:"_buttons_a8nxk_23",chancelButton:"_chancelButton_a8nxk_30",confirmButton:"_confirmButton_a8nxk_32"},b=()=>{const[n,i]=e.useState([]);return[n,()=>{(async()=>{const d=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0}),u=await navigator.mediaDevices.enumerateDevices();i(u),d.getTracks().forEach(o=>o.stop())})()}]},I=({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 d=o=>{a(o.target.value)},u=`device-select-${i.toLowerCase().replace(/\s/g,"-")}`;return e.createElement(e.Fragment,null,e.createElement("label",{htmlFor:u},i),e.createElement("select",{id:u,onChange:d},n.map((o,v)=>e.createElement(I,{value:o.deviceId,name:o.label,key:v}))))},h=({className:n,children:i,onClick:a})=>e.createElement("button",{onClick:a,className:[n].filter(Boolean).join(" ")},i),B=({isSelectAudioInput:n=!0,isSelectAudioOutput:i=!0,isSelectVideoInput:a=!0,open:d,audioInputDeviceLabel:u="audio input device",audioOutputDeviceLabel:o="audio output device",videoInputDeviceLabel:v="video input device",confirmButtonText:x="Confirm",cancelButtonText:L="Cancel",allowOutsideClick:D=!0,onDeviceSelected:M,onDeviceSelectCanceled:k})=>{const[m,S]=b(),[E,N]=e.useState(),[C,y]=e.useState(),[_,O]=e.useState(),p=m.filter(t=>t.kind==="audioinput"),f=m.filter(t=>t.kind==="audiooutput"),g=m.filter(t=>t.kind==="videoinput");e.useEffect(()=>{S()},[]);const A=()=>{M({audioInput:E!==void 0?E:p[0],audioOutput:C!==void 0?C:f[0],videoInput:_!==void 0?_:g[0]})},F=()=>{k()},T=t=>{N(p.find(l=>l.deviceId===t))},j=t=>{y(f.find(l=>l.deviceId===t))},w=t=>{O(g.find(l=>l.deviceId===t))},P=()=>{k()};return d?e.createElement("div",{className:s.background,...D?{onClick:P}:{}},e.createElement("div",{className:s.modal,...D?{onClick:t=>t.stopPropagation()}:{}},e.createElement("div",{className:s.deviceLists},n&&e.createElement(r,{label:u,devices:p,onChange:T}),i&&e.createElement(r,{label:o,devices:f,onChange:j}),a&&e.createElement(r,{label:v,devices:g,onChange:w})),e.createElement("div",{className:s.buttons},e.createElement(h,{className:s.cancelButton,onClick:F},L),e.createElement(h,{className:s.confirmButton,onClick:A},x)))):e.createElement(e.Fragment,null)};c.SelectMediaDevicesModal=B,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
@@ -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.7",
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
  }