@canonical/react-components 0.50.5 → 0.51.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.
@@ -26,5 +26,10 @@ export type Props = PropsWithSpread<{
26
26
  */
27
27
  title?: ReactNode;
28
28
  }, HTMLProps<HTMLDivElement>>;
29
+ /**
30
+ * This is a [React](https://reactjs.org/) component for the Vanilla [Card](https://docs.vanillaframework.io/patterns/card/).
31
+ *
32
+ * There are four card styles available to use in Vanilla: default, header, highlighted and overlay. Our card component will expand to fill the full width of its parent container.
33
+ */
29
34
  declare const Card: ({ children, className, highlighted, overlay, thumbnail, title, ...props }: Props) => JSX.Element;
30
35
  export default Card;
@@ -10,6 +10,12 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
10
10
  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; }
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
  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); }
13
+ /**
14
+ * This is a [React](https://reactjs.org/) component for the Vanilla [Card](https://docs.vanillaframework.io/patterns/card/).
15
+ *
16
+ * There are four card styles available to use in Vanilla: default, header, highlighted and overlay. Our card component will expand to fill the full width of its parent container.
17
+ */
18
+
13
19
  const Card = _ref => {
14
20
  let {
15
21
  children,
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import type { Meta } from "@storybook/react";
3
+ import Card from "./";
4
+ declare const meta: Meta<typeof Card>;
5
+ export default meta;
6
+ export declare const Default: {
7
+ args: {
8
+ title: string;
9
+ children: string;
10
+ };
11
+ };
12
+ export declare const Header: {
13
+ args: {
14
+ title: string;
15
+ thumbnail: string;
16
+ children: string;
17
+ };
18
+ };
19
+ export declare const Highlighted: {
20
+ args: {
21
+ highlighted: boolean;
22
+ title: string;
23
+ children: string;
24
+ };
25
+ };
26
+ export declare const Overlay: {
27
+ args: {
28
+ title: string;
29
+ overlay: boolean;
30
+ children: string;
31
+ };
32
+ render: (args: any) => React.JSX.Element;
33
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.Overlay = exports.Highlighted = exports.Header = exports.Default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _ = _interopRequireDefault(require("./"));
9
+ var _Col = _interopRequireDefault(require("../Col"));
10
+ var _Row = _interopRequireDefault(require("../Row"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ const meta = {
13
+ title: "Card",
14
+ component: _.default,
15
+ tags: ["autodocs"]
16
+ };
17
+ var _default = exports.default = meta;
18
+ const Default = exports.Default = {
19
+ args: {
20
+ title: "We'd love to have you join us as a partner.",
21
+ children: "If you are an independent software vendor or bundle author, it's easy to apply. You can find out more below."
22
+ }
23
+ };
24
+ const Header = exports.Header = {
25
+ args: {
26
+ title: "Raspberry Pi2 and Pi3",
27
+ thumbnail: "https://assets.ubuntu.com/v1/dca2e4c4-raspberry-logo.png",
28
+ children: "For fun, for education and for profit, the RPi makes device development personal and entertaining. With support for both the Pi2 and the new Pi3, Ubuntu Core supports the world’s most beloved board."
29
+ }
30
+ };
31
+ const Highlighted = exports.Highlighted = {
32
+ args: {
33
+ ...Default.args,
34
+ highlighted: true
35
+ }
36
+ };
37
+ const Overlay = exports.Overlay = {
38
+ args: {
39
+ title: "Web browsing",
40
+ overlay: true,
41
+ children: "Renowned for speed and security, Ubuntu and Firefox make browsing\nthe web a pleasure again. Ubuntu also includes Chrome, Opera and\nother browsers that can be installed from the Ubuntu Software\nCentre."
42
+ },
43
+ render: args => /*#__PURE__*/_react.default.createElement("section", {
44
+ className: "p-strip--image is-light",
45
+ style: {
46
+ backgroundImage: "url('https://assets.ubuntu.com/v1/0a98afcd-screenshot_desktop.jpg')"
47
+ }
48
+ }, /*#__PURE__*/_react.default.createElement(_Row.default, null, /*#__PURE__*/_react.default.createElement(_Col.default, {
49
+ size: 6,
50
+ emptyLarge: 7
51
+ }, /*#__PURE__*/_react.default.createElement(_.default, args))))
52
+ };
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { type ComponentProps, type ComponentType, type ElementType, type HTMLProps } from "react";
3
+ import Input from "../Input";
4
+ export type Props<C extends ElementType | ComponentType = typeof Input> = {
5
+ /**
6
+ * The component to display.
7
+ * @default Input
8
+ */
9
+ component?: C;
10
+ /**
11
+ * This can be used to hide errors returned by Formik.
12
+ */
13
+ displayError?: boolean;
14
+ /**
15
+ * The name of the field as given to Formik.
16
+ */
17
+ name: string;
18
+ value?: HTMLProps<HTMLElement>["value"];
19
+ } & ComponentProps<C>;
20
+ /**
21
+ * This component makes it easier to use Vanilla form inputs with Formik. It
22
+ * makes use of Formik's context to automatically map errors, values, states
23
+ * etc. onto the provided field.
24
+ */
25
+ declare const FormikField: <C extends React.ElementType | React.ComponentType = ({ caution, className, error, help, helpClassName, id, label, labelClassName, required, stacked, success, takeFocus, takeFocusDelay, type, wrapperClassName, ...inputProps }: import("../Input").InputProps) => JSX.Element>({ component: Component, displayError, name, value, label, ...props }: Props<C>) => JSX.Element;
26
+ export default FormikField;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _formik = require("formik");
9
+ var _Input = _interopRequireDefault(require("../Input"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ 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); }
12
+ /**
13
+ * This component makes it easier to use Vanilla form inputs with Formik. It
14
+ * makes use of Formik's context to automatically map errors, values, states
15
+ * etc. onto the provided field.
16
+ */
17
+ const FormikField = _ref => {
18
+ let {
19
+ component: Component = _Input.default,
20
+ displayError = true,
21
+ name,
22
+ value,
23
+ label,
24
+ ...props
25
+ } = _ref;
26
+ const [field, meta] = (0, _formik.useField)({
27
+ name,
28
+ type: props.type,
29
+ value
30
+ });
31
+ return /*#__PURE__*/_react.default.createElement(Component, _extends({
32
+ "aria-label": label,
33
+ error: meta.touched && displayError ? meta.error : null,
34
+ label: label
35
+ }, field, props));
36
+ };
37
+ var _default = exports.default = FormikField;
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import FormikField from "./FormikField";
3
+ declare const meta: Meta<typeof FormikField>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof FormikField>;
6
+ export declare const Default: Story;
7
+ export declare const Fields: Story;
8
+ export declare const Errors: Story;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.Fields = exports.Errors = exports.Default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _FormikField = _interopRequireDefault(require("./FormikField"));
9
+ var _Select = _interopRequireDefault(require("../Select"));
10
+ var _formik = require("formik");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ const meta = {
13
+ title: "FormikField",
14
+ component: _FormikField.default,
15
+ tags: ["autodocs"]
16
+ };
17
+ var _default = exports.default = meta;
18
+ const Default = exports.Default = {
19
+ args: {
20
+ name: "username",
21
+ label: "Username",
22
+ type: "text"
23
+ },
24
+ render: args => /*#__PURE__*/_react.default.createElement(_formik.Formik, {
25
+ initialValues: {
26
+ username: ""
27
+ },
28
+ onSubmit: () => {}
29
+ }, /*#__PURE__*/_react.default.createElement(_FormikField.default, args))
30
+ };
31
+ const Fields = exports.Fields = {
32
+ args: {
33
+ component: _Select.default,
34
+ name: "release",
35
+ label: "Release",
36
+ options: [{
37
+ value: "",
38
+ disabled: true,
39
+ label: "Select an option"
40
+ }, {
41
+ value: "1",
42
+ label: "Cosmic Cuttlefish"
43
+ }, {
44
+ value: "2",
45
+ label: "Bionic Beaver"
46
+ }, {
47
+ value: "3",
48
+ label: "Xenial Xerus"
49
+ }]
50
+ },
51
+ parameters: {
52
+ docs: {
53
+ description: {
54
+ story: "\nAny React Components input can be provided to FormikField (e.g. Input, Textarea or Select) or you may provide a custom component.\n\nAny additional props that need to be passed can be given to FormikField.\n "
55
+ }
56
+ }
57
+ },
58
+ render: args => /*#__PURE__*/_react.default.createElement(_formik.Formik, {
59
+ initialValues: {
60
+ release: ""
61
+ },
62
+ onSubmit: () => {}
63
+ }, /*#__PURE__*/_react.default.createElement(_FormikField.default, args))
64
+ };
65
+ const Errors = exports.Errors = {
66
+ args: Default.args,
67
+ parameters: {
68
+ docs: {
69
+ description: {
70
+ story: "\nFormik parameters are passed to the field using Formik's `useField`. This means that validation and errors, state handlers etc. should all just work.\n "
71
+ }
72
+ }
73
+ },
74
+ render: args => /*#__PURE__*/_react.default.createElement(_formik.Formik, {
75
+ initialErrors: {
76
+ username: "This username has already been taken."
77
+ },
78
+ initialTouched: {
79
+ username: true
80
+ },
81
+ initialValues: {
82
+ username: ""
83
+ },
84
+ onSubmit: () => {}
85
+ }, /*#__PURE__*/_react.default.createElement(_FormikField.default, args))
86
+ };
@@ -0,0 +1 @@
1
+ export { default, type Props as FormikFieldProps } from "./FormikField";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _FormikField.default;
10
+ }
11
+ });
12
+ var _FormikField = _interopRequireDefault(require("./FormikField"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -1,7 +1,4 @@
1
- @import "~vanilla-framework/scss/settings";
2
- @import "~vanilla-framework/scss/base_placeholders";
3
- @import "~vanilla-framework/scss/base_icon-definitions";
4
- @import "~vanilla-framework/scss/patterns_icons";
1
+ @import "vanilla-framework";
5
2
 
6
3
  @include vf-b-placeholders;
7
4
  @include vf-p-icons-common;
@@ -49,7 +49,6 @@ const Input = _ref => {
49
49
  "aria-errormessage": hasError ? validationId : null,
50
50
  "aria-invalid": hasError,
51
51
  id: inputId,
52
- label: label,
53
52
  required: required,
54
53
  ...inputProps
55
54
  };
@@ -1,11 +1,15 @@
1
1
  @use "sass:map";
2
2
  @import "vanilla-framework";
3
- @include vf-base;
4
- @include vf-p-lists;
3
+ @include vf-b-placeholders; // Vanilla base placeholders to extend from
5
4
 
6
5
  $dropdown-max-height: 20rem;
7
6
 
8
7
  .multi-select {
8
+ // Scope Vanilla form includes to multi select component only
9
+ // to avoid overriding any Vanilla base styles
10
+ // XXX: This is a workaround for https://github.com/canonical/vanilla-framework/issues/5030
11
+ @include vf-b-forms;
12
+
9
13
  position: relative;
10
14
  }
11
15
 
@@ -37,12 +41,12 @@ $dropdown-max-height: 20rem;
37
41
  }
38
42
 
39
43
  .multi-select__dropdown {
40
- @extend %vf-bg--x-light;
41
- @extend %vf-has-box-shadow;
44
+ background-color: $colors--theme--background-default;
45
+ box-shadow: $box-shadow;
46
+ color: $colors--theme--text-default;
42
47
  left: 0;
43
48
  max-height: $dropdown-max-height;
44
49
  overflow: auto;
45
-
46
50
  padding-top: $spv--small;
47
51
  position: absolute;
48
52
  right: 0;
@@ -59,14 +63,15 @@ $dropdown-max-height: 20rem;
59
63
  }
60
64
 
61
65
  .multi-select__dropdown-list {
62
- @extend %vf-list;
63
-
66
+ list-style: none;
64
67
  margin-bottom: $sph--x-small;
68
+ margin-left: 0;
69
+ padding-left: 0;
65
70
  }
66
71
 
67
72
  .multi-select__footer {
68
- background: white;
69
- border-top: 1px solid $color-mid-light;
73
+ background: $colors--theme--background-default;
74
+ border-top: 1px solid $colors--theme--border-default;
70
75
  bottom: 0;
71
76
  display: flex;
72
77
  flex-wrap: wrap;
@@ -97,12 +102,6 @@ $dropdown-max-height: 20rem;
97
102
  }
98
103
  }
99
104
 
100
- .multi-select__dropdown-item-description {
101
- @extend %small-text;
102
-
103
- color: $color-mid-dark;
104
- }
105
-
106
105
  .multi-select__dropdown-button {
107
106
  border: 0;
108
107
  margin-bottom: 0;
@@ -113,7 +112,7 @@ $dropdown-max-height: 20rem;
113
112
  }
114
113
 
115
114
  .multi-select__selected-list {
116
- background-color: $colors--light-theme--background-inputs;
115
+ background-color: $colors--theme--background-inputs;
117
116
  border-bottom: 0;
118
117
  margin: 0;
119
118
  overflow: hidden;
@@ -142,12 +141,12 @@ $dropdown-max-height: 20rem;
142
141
  transform: translateY(-50%) rotate(-180deg);
143
142
 
144
143
  @extend %icon;
145
- @include vf-icon-chevron($color-mid-dark);
144
+ @include vf-icon-chevron-themed;
146
145
  @include vf-transition($property: transform, $duration: fast);
147
146
  }
148
147
 
149
148
  &[aria-expanded="true"] {
150
- background-color: $colors--light-theme--background-hover;
149
+ background-color: $colors--theme--background-hover;
151
150
  }
152
151
 
153
152
  &[aria-expanded="false"] {
@@ -85,9 +85,11 @@ const PaginationItemSeparator = () => /*#__PURE__*/_react.default.createElement(
85
85
  // current page and paginate function is defined. Pagination
86
86
  // is handled by paginate function and optional onForward and
87
87
  // onBack functions.
88
+
88
89
  // Used when number of items per page, number of total items,
89
90
  // current page and paginate function are undefined.
90
91
  // Pagination is handled by onForward and onBack function.
92
+
91
93
  const Pagination = _ref => {
92
94
  let {
93
95
  itemsPerPage,
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export { default as ContextualMenu } from "./components/ContextualMenu";
15
15
  export { default as EmptyState } from "./components/EmptyState";
16
16
  export { default as Field } from "./components/Field";
17
17
  export { default as Form } from "./components/Form";
18
+ export { default as FormikField } from "./components/FormikField";
18
19
  export { default as Icon, ICONS } from "./components/Icon";
19
20
  export { default as Input } from "./components/Input";
20
21
  export { default as Label } from "./components/Label";
@@ -66,6 +67,7 @@ export type { ContextualMenuProps, ContextualMenuDropdownProps, MenuLink, Positi
66
67
  export type { EmptyStateProps } from "./components/EmptyState";
67
68
  export type { FieldProps } from "./components/Field";
68
69
  export type { FormProps } from "./components/Form";
70
+ export type { FormikFieldProps } from "./components/FormikField";
69
71
  export type { IconProps } from "./components/Icon";
70
72
  export type { InputProps } from "./components/Input";
71
73
  export type { LabelProps } from "./components/Label";
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ var _exportNames = {
23
23
  EmptyState: true,
24
24
  Field: true,
25
25
  Form: true,
26
+ FormikField: true,
26
27
  Icon: true,
27
28
  ICONS: true,
28
29
  Input: true,
@@ -192,6 +193,12 @@ Object.defineProperty(exports, "Form", {
192
193
  return _Form.default;
193
194
  }
194
195
  });
196
+ Object.defineProperty(exports, "FormikField", {
197
+ enumerable: true,
198
+ get: function () {
199
+ return _FormikField.default;
200
+ }
201
+ });
195
202
  Object.defineProperty(exports, "ICONS", {
196
203
  enumerable: true,
197
204
  get: function () {
@@ -533,6 +540,7 @@ var _ContextualMenu = _interopRequireDefault(require("./components/ContextualMen
533
540
  var _EmptyState = _interopRequireDefault(require("./components/EmptyState"));
534
541
  var _Field = _interopRequireDefault(require("./components/Field"));
535
542
  var _Form = _interopRequireDefault(require("./components/Form"));
543
+ var _FormikField = _interopRequireDefault(require("./components/FormikField"));
536
544
  var _Icon = _interopRequireWildcard(require("./components/Icon"));
537
545
  var _Input = _interopRequireDefault(require("./components/Input"));
538
546
  var _Label = _interopRequireDefault(require("./components/Label"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "0.50.5",
3
+ "version": "0.51.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "Huw Wilkins <huw.wilkins@canonical.com>",
@@ -66,6 +66,7 @@
66
66
  "eslint-plugin-react-hooks": "4.6.0",
67
67
  "eslint-plugin-storybook": "0.6.15",
68
68
  "eslint-plugin-testing-library": "6.2.0",
69
+ "formik": "2.4.5",
69
70
  "jest": "29.7.0",
70
71
  "npm-package-json-lint": "7.1.0",
71
72
  "prettier": "3.2.4",
@@ -85,7 +86,7 @@
85
86
  "ts-jest": "29.1.2",
86
87
  "tsc-alias": "1.8.8",
87
88
  "typescript": "5.3.3",
88
- "vanilla-framework": "4.6.0",
89
+ "vanilla-framework": "4.9.0",
89
90
  "wait-on": "7.2.0",
90
91
  "webpack": "5.89.0"
91
92
  },
@@ -111,6 +112,7 @@
111
112
  "peerDependencies": {
112
113
  "@types/react": "^17.0.2 || ^18.0.0",
113
114
  "@types/react-dom": "^17.0.2 || ^18.0.0",
115
+ "formik": "^2.4.5",
114
116
  "react": "^17.0.2 || ^18.0.0",
115
117
  "react-dom": "^17.0.2 || ^18.0.0",
116
118
  "vanilla-framework": "^3.15.1 || ^4.0.0"