@canonical/react-components 2.3.1 → 2.5.0
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/dist/components/EventQueue/EventQueue.d.ts +51 -0
- package/dist/components/EventQueue/EventQueue.js +74 -0
- package/dist/components/EventQueue/EventQueueProvider.test.d.ts +1 -0
- package/dist/components/EventQueue/index.d.ts +2 -0
- package/dist/components/EventQueue/index.js +12 -0
- package/dist/components/Stepper/Step/Step.scss +1 -1
- package/dist/components/Switch/Switch.d.ts +10 -1
- package/dist/components/Switch/Switch.js +13 -3
- package/dist/components/Switch/Switch.scss +3 -0
- package/dist/components/Switch/Switch.stories.d.ts +1 -0
- package/dist/components/Switch/Switch.stories.js +8 -1
- package/dist/esm/components/EventQueue/EventQueue.d.ts +51 -0
- package/dist/esm/components/EventQueue/EventQueue.js +67 -0
- package/dist/esm/components/EventQueue/EventQueueProvider.test.d.ts +1 -0
- package/dist/esm/components/EventQueue/index.d.ts +2 -0
- package/dist/esm/components/EventQueue/index.js +1 -0
- package/dist/esm/components/Stepper/Step/Step.scss +1 -1
- package/dist/esm/components/Switch/Switch.d.ts +10 -1
- package/dist/esm/components/Switch/Switch.js +13 -4
- package/dist/esm/components/Switch/Switch.scss +3 -0
- package/dist/esm/components/Switch/Switch.stories.d.ts +1 -0
- package/dist/esm/components/Switch/Switch.stories.js +7 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FC, ReactNode } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export interface EventCallback<T> {
|
|
4
|
+
onSuccess: (event: T) => void;
|
|
5
|
+
onFailure: (msg: string) => void;
|
|
6
|
+
onFinish?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface EventQueue<T> {
|
|
9
|
+
get: (operationId: string) => EventCallback<T> | undefined;
|
|
10
|
+
set: (operationId: string, onSuccess: (event: T) => void, onFailure: (msg: string) => void, onFinish?: () => void) => void;
|
|
11
|
+
remove: (operationId: string) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* This provides an event queue system for managing callbacks associated with
|
|
15
|
+
* asynchronous operations (e.g., API calls) in an application.
|
|
16
|
+
*
|
|
17
|
+
* It allows components to register success, failure,
|
|
18
|
+
* and optional finish handlers for a given operation ID, and later retrieve or remove them.
|
|
19
|
+
*
|
|
20
|
+
* This is useful for handling side effects when dealing
|
|
21
|
+
* with multiple operations that need to be tracked and updated independently.
|
|
22
|
+
*
|
|
23
|
+
* The `createEventQueue` function should be used to create a single provider and context that are shared throughout your application.
|
|
24
|
+
* The returned `EventQueueProvider` and `useEventQueue` hook should be exported
|
|
25
|
+
* from a shared module and reused across the app to ensure a single
|
|
26
|
+
* context instance is used.
|
|
27
|
+
*
|
|
28
|
+
* Usage pattern:
|
|
29
|
+
* // eventQueue.ts
|
|
30
|
+
* export const { EventQueueProvider, useEventQueue } = createEventQueue<EventType>();
|
|
31
|
+
*
|
|
32
|
+
* // App.tsx
|
|
33
|
+
* import { EventQueueProvider } from "./eventQueue";
|
|
34
|
+
* ...
|
|
35
|
+
* <EventQueueProvider>
|
|
36
|
+
* <App />
|
|
37
|
+
* </EventQueueProvider>
|
|
38
|
+
*
|
|
39
|
+
* // In any other component
|
|
40
|
+
* import { useEventQueue } from "./eventQueue";
|
|
41
|
+
* ...
|
|
42
|
+
* const eventQueue = useEventQueue();
|
|
43
|
+
* eventQueue.set(operationId, onSuccess, onFailure);
|
|
44
|
+
*/
|
|
45
|
+
export declare function createEventQueue<T>(): {
|
|
46
|
+
EventQueueProvider: FC<{
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
}>;
|
|
49
|
+
useEventQueue: () => EventQueue<T>;
|
|
50
|
+
EventQueueContext: React.Context<EventQueue<T>>;
|
|
51
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createEventQueue = createEventQueue;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
+
/**
|
|
11
|
+
* This provides an event queue system for managing callbacks associated with
|
|
12
|
+
* asynchronous operations (e.g., API calls) in an application.
|
|
13
|
+
*
|
|
14
|
+
* It allows components to register success, failure,
|
|
15
|
+
* and optional finish handlers for a given operation ID, and later retrieve or remove them.
|
|
16
|
+
*
|
|
17
|
+
* This is useful for handling side effects when dealing
|
|
18
|
+
* with multiple operations that need to be tracked and updated independently.
|
|
19
|
+
*
|
|
20
|
+
* The `createEventQueue` function should be used to create a single provider and context that are shared throughout your application.
|
|
21
|
+
* The returned `EventQueueProvider` and `useEventQueue` hook should be exported
|
|
22
|
+
* from a shared module and reused across the app to ensure a single
|
|
23
|
+
* context instance is used.
|
|
24
|
+
*
|
|
25
|
+
* Usage pattern:
|
|
26
|
+
* // eventQueue.ts
|
|
27
|
+
* export const { EventQueueProvider, useEventQueue } = createEventQueue<EventType>();
|
|
28
|
+
*
|
|
29
|
+
* // App.tsx
|
|
30
|
+
* import { EventQueueProvider } from "./eventQueue";
|
|
31
|
+
* ...
|
|
32
|
+
* <EventQueueProvider>
|
|
33
|
+
* <App />
|
|
34
|
+
* </EventQueueProvider>
|
|
35
|
+
*
|
|
36
|
+
* // In any other component
|
|
37
|
+
* import { useEventQueue } from "./eventQueue";
|
|
38
|
+
* ...
|
|
39
|
+
* const eventQueue = useEventQueue();
|
|
40
|
+
* eventQueue.set(operationId, onSuccess, onFailure);
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
function createEventQueue() {
|
|
44
|
+
const EventQueueContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
45
|
+
const eventQueue = new Map();
|
|
46
|
+
const EventQueueProvider = _ref => {
|
|
47
|
+
let {
|
|
48
|
+
children
|
|
49
|
+
} = _ref;
|
|
50
|
+
return /*#__PURE__*/_react.default.createElement(EventQueueContext.Provider, {
|
|
51
|
+
value: {
|
|
52
|
+
get: operationId => eventQueue.get(operationId),
|
|
53
|
+
set: (operationId, onSuccess, onFailure, onFinish) => eventQueue.set(operationId, {
|
|
54
|
+
onSuccess,
|
|
55
|
+
onFailure,
|
|
56
|
+
onFinish
|
|
57
|
+
}),
|
|
58
|
+
remove: operationId => eventQueue.delete(operationId)
|
|
59
|
+
}
|
|
60
|
+
}, children);
|
|
61
|
+
};
|
|
62
|
+
const useEventQueue = () => {
|
|
63
|
+
const context = (0, _react.useContext)(EventQueueContext);
|
|
64
|
+
if (!context) {
|
|
65
|
+
throw new Error("useEventQueue must be used within an EventQueueProvider");
|
|
66
|
+
}
|
|
67
|
+
return context;
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
EventQueueProvider,
|
|
71
|
+
useEventQueue,
|
|
72
|
+
EventQueueContext
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "createEventQueue", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _EventQueue.createEventQueue;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _EventQueue = require("./EventQueue");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { HTMLProps, ReactNode } from "react";
|
|
3
3
|
import type { PropsWithSpread } from "../../types";
|
|
4
|
+
import "./Switch.scss";
|
|
4
5
|
export type Props = PropsWithSpread<{
|
|
5
6
|
/**
|
|
6
7
|
* The label name for the switch
|
|
@@ -10,9 +11,17 @@ export type Props = PropsWithSpread<{
|
|
|
10
11
|
* Whether the switch is disabled or not
|
|
11
12
|
*/
|
|
12
13
|
disabled?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Help text to show below the field.
|
|
16
|
+
*/
|
|
17
|
+
help?: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Optional class(es) to pass to the help text element.
|
|
20
|
+
*/
|
|
21
|
+
helpClassName?: string;
|
|
13
22
|
}, HTMLProps<HTMLInputElement>>;
|
|
14
23
|
/**
|
|
15
24
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Switch](https://vanillaframework.io/docs/patterns/switch) component.
|
|
16
25
|
*/
|
|
17
|
-
export declare const Switch: ({ label, disabled, ...inputProps }: Props) => React.JSX.Element;
|
|
26
|
+
export declare const Switch: ({ label, disabled, help, helpClassName, ...inputProps }: Props) => React.JSX.Element;
|
|
18
27
|
export default Switch;
|
|
@@ -4,8 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Switch = void 0;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
require("./Switch.scss");
|
|
8
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
13
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
10
14
|
/**
|
|
11
15
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Switch](https://vanillaframework.io/docs/patterns/switch) component.
|
|
@@ -14,9 +18,12 @@ const Switch = _ref => {
|
|
|
14
18
|
let {
|
|
15
19
|
label,
|
|
16
20
|
disabled = false,
|
|
21
|
+
help,
|
|
22
|
+
helpClassName,
|
|
17
23
|
...inputProps
|
|
18
24
|
} = _ref;
|
|
19
|
-
|
|
25
|
+
const helpId = (0, _react.useId)();
|
|
26
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("label", {
|
|
20
27
|
className: "p-switch"
|
|
21
28
|
}, /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
22
29
|
type: "checkbox",
|
|
@@ -27,7 +34,10 @@ const Switch = _ref => {
|
|
|
27
34
|
className: "p-switch__slider"
|
|
28
35
|
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
29
36
|
className: "p-switch__label"
|
|
30
|
-
}, label))
|
|
37
|
+
}, label)), help && /*#__PURE__*/_react.default.createElement("p", {
|
|
38
|
+
className: (0, _classnames.default)("p-form-help-text", "switch-help-text", helpClassName),
|
|
39
|
+
id: helpId
|
|
40
|
+
}, help));
|
|
31
41
|
};
|
|
32
42
|
exports.Switch = Switch;
|
|
33
43
|
var _default = exports.default = Switch;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.Disabled = exports.Default = void 0;
|
|
6
|
+
exports.default = exports.HelpText = exports.Disabled = exports.Default = void 0;
|
|
7
7
|
var _Switch = _interopRequireDefault(require("./Switch"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
9
|
const meta = {
|
|
@@ -23,4 +23,11 @@ const Disabled = exports.Disabled = {
|
|
|
23
23
|
disabled: true,
|
|
24
24
|
label: "Disabled switch"
|
|
25
25
|
}
|
|
26
|
+
};
|
|
27
|
+
const HelpText = exports.HelpText = {
|
|
28
|
+
name: "Help Text",
|
|
29
|
+
args: {
|
|
30
|
+
label: "Switch with help text",
|
|
31
|
+
help: "This is some help text"
|
|
32
|
+
}
|
|
26
33
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FC, ReactNode } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export interface EventCallback<T> {
|
|
4
|
+
onSuccess: (event: T) => void;
|
|
5
|
+
onFailure: (msg: string) => void;
|
|
6
|
+
onFinish?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface EventQueue<T> {
|
|
9
|
+
get: (operationId: string) => EventCallback<T> | undefined;
|
|
10
|
+
set: (operationId: string, onSuccess: (event: T) => void, onFailure: (msg: string) => void, onFinish?: () => void) => void;
|
|
11
|
+
remove: (operationId: string) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* This provides an event queue system for managing callbacks associated with
|
|
15
|
+
* asynchronous operations (e.g., API calls) in an application.
|
|
16
|
+
*
|
|
17
|
+
* It allows components to register success, failure,
|
|
18
|
+
* and optional finish handlers for a given operation ID, and later retrieve or remove them.
|
|
19
|
+
*
|
|
20
|
+
* This is useful for handling side effects when dealing
|
|
21
|
+
* with multiple operations that need to be tracked and updated independently.
|
|
22
|
+
*
|
|
23
|
+
* The `createEventQueue` function should be used to create a single provider and context that are shared throughout your application.
|
|
24
|
+
* The returned `EventQueueProvider` and `useEventQueue` hook should be exported
|
|
25
|
+
* from a shared module and reused across the app to ensure a single
|
|
26
|
+
* context instance is used.
|
|
27
|
+
*
|
|
28
|
+
* Usage pattern:
|
|
29
|
+
* // eventQueue.ts
|
|
30
|
+
* export const { EventQueueProvider, useEventQueue } = createEventQueue<EventType>();
|
|
31
|
+
*
|
|
32
|
+
* // App.tsx
|
|
33
|
+
* import { EventQueueProvider } from "./eventQueue";
|
|
34
|
+
* ...
|
|
35
|
+
* <EventQueueProvider>
|
|
36
|
+
* <App />
|
|
37
|
+
* </EventQueueProvider>
|
|
38
|
+
*
|
|
39
|
+
* // In any other component
|
|
40
|
+
* import { useEventQueue } from "./eventQueue";
|
|
41
|
+
* ...
|
|
42
|
+
* const eventQueue = useEventQueue();
|
|
43
|
+
* eventQueue.set(operationId, onSuccess, onFailure);
|
|
44
|
+
*/
|
|
45
|
+
export declare function createEventQueue<T>(): {
|
|
46
|
+
EventQueueProvider: FC<{
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
}>;
|
|
49
|
+
useEventQueue: () => EventQueue<T>;
|
|
50
|
+
EventQueueContext: React.Context<EventQueue<T>>;
|
|
51
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
/**
|
|
4
|
+
* This provides an event queue system for managing callbacks associated with
|
|
5
|
+
* asynchronous operations (e.g., API calls) in an application.
|
|
6
|
+
*
|
|
7
|
+
* It allows components to register success, failure,
|
|
8
|
+
* and optional finish handlers for a given operation ID, and later retrieve or remove them.
|
|
9
|
+
*
|
|
10
|
+
* This is useful for handling side effects when dealing
|
|
11
|
+
* with multiple operations that need to be tracked and updated independently.
|
|
12
|
+
*
|
|
13
|
+
* The `createEventQueue` function should be used to create a single provider and context that are shared throughout your application.
|
|
14
|
+
* The returned `EventQueueProvider` and `useEventQueue` hook should be exported
|
|
15
|
+
* from a shared module and reused across the app to ensure a single
|
|
16
|
+
* context instance is used.
|
|
17
|
+
*
|
|
18
|
+
* Usage pattern:
|
|
19
|
+
* // eventQueue.ts
|
|
20
|
+
* export const { EventQueueProvider, useEventQueue } = createEventQueue<EventType>();
|
|
21
|
+
*
|
|
22
|
+
* // App.tsx
|
|
23
|
+
* import { EventQueueProvider } from "./eventQueue";
|
|
24
|
+
* ...
|
|
25
|
+
* <EventQueueProvider>
|
|
26
|
+
* <App />
|
|
27
|
+
* </EventQueueProvider>
|
|
28
|
+
*
|
|
29
|
+
* // In any other component
|
|
30
|
+
* import { useEventQueue } from "./eventQueue";
|
|
31
|
+
* ...
|
|
32
|
+
* const eventQueue = useEventQueue();
|
|
33
|
+
* eventQueue.set(operationId, onSuccess, onFailure);
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export function createEventQueue() {
|
|
37
|
+
var EventQueueContext = /*#__PURE__*/createContext(undefined);
|
|
38
|
+
var eventQueue = new Map();
|
|
39
|
+
var EventQueueProvider = _ref => {
|
|
40
|
+
var {
|
|
41
|
+
children
|
|
42
|
+
} = _ref;
|
|
43
|
+
return /*#__PURE__*/React.createElement(EventQueueContext.Provider, {
|
|
44
|
+
value: {
|
|
45
|
+
get: operationId => eventQueue.get(operationId),
|
|
46
|
+
set: (operationId, onSuccess, onFailure, onFinish) => eventQueue.set(operationId, {
|
|
47
|
+
onSuccess,
|
|
48
|
+
onFailure,
|
|
49
|
+
onFinish
|
|
50
|
+
}),
|
|
51
|
+
remove: operationId => eventQueue.delete(operationId)
|
|
52
|
+
}
|
|
53
|
+
}, children);
|
|
54
|
+
};
|
|
55
|
+
var useEventQueue = () => {
|
|
56
|
+
var context = useContext(EventQueueContext);
|
|
57
|
+
if (!context) {
|
|
58
|
+
throw new Error("useEventQueue must be used within an EventQueueProvider");
|
|
59
|
+
}
|
|
60
|
+
return context;
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
EventQueueProvider,
|
|
64
|
+
useEventQueue,
|
|
65
|
+
EventQueueContext
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createEventQueue } from "./EventQueue";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { HTMLProps, ReactNode } from "react";
|
|
3
3
|
import type { PropsWithSpread } from "../../types";
|
|
4
|
+
import "./Switch.scss";
|
|
4
5
|
export type Props = PropsWithSpread<{
|
|
5
6
|
/**
|
|
6
7
|
* The label name for the switch
|
|
@@ -10,9 +11,17 @@ export type Props = PropsWithSpread<{
|
|
|
10
11
|
* Whether the switch is disabled or not
|
|
11
12
|
*/
|
|
12
13
|
disabled?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Help text to show below the field.
|
|
16
|
+
*/
|
|
17
|
+
help?: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Optional class(es) to pass to the help text element.
|
|
20
|
+
*/
|
|
21
|
+
helpClassName?: string;
|
|
13
22
|
}, HTMLProps<HTMLInputElement>>;
|
|
14
23
|
/**
|
|
15
24
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Switch](https://vanillaframework.io/docs/patterns/switch) component.
|
|
16
25
|
*/
|
|
17
|
-
export declare const Switch: ({ label, disabled, ...inputProps }: Props) => React.JSX.Element;
|
|
26
|
+
export declare const Switch: ({ label, disabled, help, helpClassName, ...inputProps }: Props) => React.JSX.Element;
|
|
18
27
|
export default Switch;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
var _excluded = ["label", "disabled"];
|
|
1
|
+
var _excluded = ["label", "disabled", "help", "helpClassName"];
|
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
5
|
import React from "react";
|
|
6
|
+
import classNames from "classnames";
|
|
7
|
+
import { useId } from "react";
|
|
8
|
+
import "./Switch.scss";
|
|
6
9
|
/**
|
|
7
10
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Switch](https://vanillaframework.io/docs/patterns/switch) component.
|
|
8
11
|
*/
|
|
9
12
|
export var Switch = _ref => {
|
|
10
13
|
var {
|
|
11
14
|
label,
|
|
12
|
-
disabled = false
|
|
15
|
+
disabled = false,
|
|
16
|
+
help,
|
|
17
|
+
helpClassName
|
|
13
18
|
} = _ref,
|
|
14
19
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
15
|
-
|
|
20
|
+
var helpId = useId();
|
|
21
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("label", {
|
|
16
22
|
className: "p-switch"
|
|
17
23
|
}, /*#__PURE__*/React.createElement("input", _extends({
|
|
18
24
|
type: "checkbox",
|
|
@@ -23,6 +29,9 @@ export var Switch = _ref => {
|
|
|
23
29
|
className: "p-switch__slider"
|
|
24
30
|
}), /*#__PURE__*/React.createElement("span", {
|
|
25
31
|
className: "p-switch__label"
|
|
26
|
-
}, label))
|
|
32
|
+
}, label)), help && /*#__PURE__*/React.createElement("p", {
|
|
33
|
+
className: classNames("p-form-help-text", "switch-help-text", helpClassName),
|
|
34
|
+
id: helpId
|
|
35
|
+
}, help));
|
|
27
36
|
};
|
|
28
37
|
export default Switch;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { default as ConfirmationModal } from "./components/ConfirmationModal";
|
|
|
21
21
|
export { default as ContextualMenu } from "./components/ContextualMenu";
|
|
22
22
|
export { default as DoughnutChart } from "./components/DoughnutChart";
|
|
23
23
|
export { default as EmptyState } from "./components/EmptyState";
|
|
24
|
+
export { createEventQueue } from "./components/EventQueue";
|
|
24
25
|
export { default as Field } from "./components/Field";
|
|
25
26
|
export { default as Form } from "./components/Form";
|
|
26
27
|
export { default as FormikField } from "./components/FormikField";
|
|
@@ -92,6 +93,7 @@ export type { ConfirmationModalProps } from "./components/ConfirmationModal";
|
|
|
92
93
|
export type { ContextualMenuProps, ContextualMenuDropdownProps, MenuLink, Position, } from "./components/ContextualMenu";
|
|
93
94
|
export type { DoughnutChartProps, Segment } from "./components/DoughnutChart";
|
|
94
95
|
export type { EmptyStateProps } from "./components/EmptyState";
|
|
96
|
+
export type { EventCallback, EventQueue } from "./components/EventQueue";
|
|
95
97
|
export type { FieldProps } from "./components/Field";
|
|
96
98
|
export type { FormProps } from "./components/Form";
|
|
97
99
|
export type { FormikFieldProps } from "./components/FormikField";
|
package/dist/esm/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export { default as ConfirmationModal } from "./components/ConfirmationModal";
|
|
|
21
21
|
export { default as ContextualMenu } from "./components/ContextualMenu";
|
|
22
22
|
export { default as DoughnutChart } from "./components/DoughnutChart";
|
|
23
23
|
export { default as EmptyState } from "./components/EmptyState";
|
|
24
|
+
export { createEventQueue } from "./components/EventQueue";
|
|
24
25
|
export { default as Field } from "./components/Field";
|
|
25
26
|
export { default as Form } from "./components/Form";
|
|
26
27
|
export { default as FormikField } from "./components/FormikField";
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { default as ConfirmationModal } from "./components/ConfirmationModal";
|
|
|
21
21
|
export { default as ContextualMenu } from "./components/ContextualMenu";
|
|
22
22
|
export { default as DoughnutChart } from "./components/DoughnutChart";
|
|
23
23
|
export { default as EmptyState } from "./components/EmptyState";
|
|
24
|
+
export { createEventQueue } from "./components/EventQueue";
|
|
24
25
|
export { default as Field } from "./components/Field";
|
|
25
26
|
export { default as Form } from "./components/Form";
|
|
26
27
|
export { default as FormikField } from "./components/FormikField";
|
|
@@ -92,6 +93,7 @@ export type { ConfirmationModalProps } from "./components/ConfirmationModal";
|
|
|
92
93
|
export type { ContextualMenuProps, ContextualMenuDropdownProps, MenuLink, Position, } from "./components/ContextualMenu";
|
|
93
94
|
export type { DoughnutChartProps, Segment } from "./components/DoughnutChart";
|
|
94
95
|
export type { EmptyStateProps } from "./components/EmptyState";
|
|
96
|
+
export type { EventCallback, EventQueue } from "./components/EventQueue";
|
|
95
97
|
export type { FieldProps } from "./components/Field";
|
|
96
98
|
export type { FormProps } from "./components/Form";
|
|
97
99
|
export type { FormikFieldProps } from "./components/FormikField";
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var _exportNames = {
|
|
|
29
29
|
ContextualMenu: true,
|
|
30
30
|
DoughnutChart: true,
|
|
31
31
|
EmptyState: true,
|
|
32
|
+
createEventQueue: true,
|
|
32
33
|
Field: true,
|
|
33
34
|
Form: true,
|
|
34
35
|
FormikField: true,
|
|
@@ -584,6 +585,12 @@ Object.defineProperty(exports, "Tooltip", {
|
|
|
584
585
|
return _Tooltip.default;
|
|
585
586
|
}
|
|
586
587
|
});
|
|
588
|
+
Object.defineProperty(exports, "createEventQueue", {
|
|
589
|
+
enumerable: true,
|
|
590
|
+
get: function () {
|
|
591
|
+
return _EventQueue.createEventQueue;
|
|
592
|
+
}
|
|
593
|
+
});
|
|
587
594
|
Object.defineProperty(exports, "failure", {
|
|
588
595
|
enumerable: true,
|
|
589
596
|
get: function () {
|
|
@@ -721,6 +728,7 @@ var _ConfirmationModal = _interopRequireDefault(require("./components/Confirmati
|
|
|
721
728
|
var _ContextualMenu = _interopRequireDefault(require("./components/ContextualMenu"));
|
|
722
729
|
var _DoughnutChart = _interopRequireDefault(require("./components/DoughnutChart"));
|
|
723
730
|
var _EmptyState = _interopRequireDefault(require("./components/EmptyState"));
|
|
731
|
+
var _EventQueue = require("./components/EventQueue");
|
|
724
732
|
var _Field = _interopRequireDefault(require("./components/Field"));
|
|
725
733
|
var _Form = _interopRequireDefault(require("./components/Form"));
|
|
726
734
|
var _FormikField = _interopRequireDefault(require("./components/FormikField"));
|