@vention/machine-ui 5.17.1 → 5.18.1

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/index.esm.js CHANGED
@@ -8880,12 +8880,14 @@ $$9({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE || BROKEN_ON_SPARSE
8880
8880
  addToUnscopables('includes');
8881
8881
 
8882
8882
  const VentionSwitch = props => {
8883
- var _a, _b;
8884
8883
  const {
8885
8884
  checked,
8886
- size,
8885
+ size = "medium",
8886
+ variant = "default",
8887
8887
  disabled,
8888
8888
  onChange,
8889
+ labelText,
8890
+ helperText,
8889
8891
  "data-testid": dataTestId = "vention-switch-root"
8890
8892
  } = props;
8891
8893
  const {
@@ -8894,8 +8896,9 @@ const VentionSwitch = props => {
8894
8896
  } = useStyles$k({
8895
8897
  checked,
8896
8898
  size,
8897
- variant: (_a = props.variant) !== null && _a !== void 0 ? _a : "default",
8898
- disabled: (_b = props.disabled) !== null && _b !== void 0 ? _b : false
8899
+ variant,
8900
+ disabled,
8901
+ helperText
8899
8902
  });
8900
8903
  const handleOnchange = () => {
8901
8904
  if (disabled) return;
@@ -8903,11 +8906,12 @@ const VentionSwitch = props => {
8903
8906
  onChange(checked === "off" ? "on" : "off");
8904
8907
  }
8905
8908
  };
8906
- return jsxs("div", {
8909
+ const switchElement = jsxs("div", {
8907
8910
  role: "switch",
8908
8911
  "aria-busy": checked === "loading" ? true : undefined,
8909
8912
  "aria-checked": getAriaChecked(checked),
8910
8913
  "aria-disabled": disabled ? true : undefined,
8914
+ "aria-label": labelText,
8911
8915
  className: classes.root,
8912
8916
  "data-testid": dataTestId,
8913
8917
  onClick: handleOnchange,
@@ -8923,17 +8927,72 @@ const VentionSwitch = props => {
8923
8927
  "data-testid": "vention-switch-thumb"
8924
8928
  })]
8925
8929
  });
8930
+ if (!labelText && !helperText) return switchElement;
8931
+ const typographyNames = getTypographyNames(size);
8932
+ return jsxs("div", {
8933
+ className: classes.container,
8934
+ "data-testid": "vention-switch-container",
8935
+ children: [jsxs("div", {
8936
+ className: classes.text,
8937
+ "data-testid": "vention-switch-text",
8938
+ onClick: handleOnchange,
8939
+ children: [labelText ? jsx(Typography, {
8940
+ variant: typographyNames.labelDiminished,
8941
+ className: classes.labelText,
8942
+ "data-testid": "vention-switch-label",
8943
+ children: labelText
8944
+ }) : null, helperText ? jsx(Typography, {
8945
+ variant: typographyNames.helperText,
8946
+ className: classes.helperText,
8947
+ "data-testid": "vention-switch-helper",
8948
+ children: helperText
8949
+ }) : null]
8950
+ }), jsx("div", {
8951
+ className: classes.box,
8952
+ children: switchElement
8953
+ })]
8954
+ });
8926
8955
  };
8927
8956
  const useStyles$k = tss.withParams().create(({
8928
8957
  theme,
8929
8958
  checked,
8930
8959
  size,
8931
8960
  variant,
8932
- disabled
8961
+ disabled,
8962
+ helperText
8933
8963
  }) => {
8934
8964
  return {
8965
+ // Text on the left, switch on the right. The switch is centred against a label on its
8966
+ // own, and top-aligned once a helper text is present.
8967
+ container: {
8968
+ display: "flex",
8969
+ gap: theme.spacing(3),
8970
+ alignItems: helperText ? "flex-start" : "center"
8971
+ },
8972
+ text: {
8973
+ cursor: disabled ? "not-allowed" : "pointer",
8974
+ display: "flex",
8975
+ flex: "1 0 0",
8976
+ flexDirection: "column",
8977
+ minWidth: 0
8978
+ },
8979
+ box: {
8980
+ display: "flex",
8981
+ alignItems: "flex-start",
8982
+ flexShrink: 0,
8983
+ paddingTop: helperText ? "2px" : 0
8984
+ },
8985
+ labelText: {
8986
+ color: theme.palette.text.primary,
8987
+ opacity: disabled ? 0.5 : 1
8988
+ },
8989
+ helperText: {
8990
+ color: theme.palette.text.secondary,
8991
+ opacity: disabled ? 0.7 : 1
8992
+ },
8935
8993
  root: Object.assign(Object.assign({
8936
8994
  backgroundColor: getBackgroundColor$1(theme, checked, variant),
8995
+ cursor: disabled ? "not-allowed" : "pointer",
8937
8996
  display: "flex",
8938
8997
  borderRadius: "999px",
8939
8998
  alignItems: "center",
@@ -8969,12 +9028,31 @@ const useStyles$k = tss.withParams().create(({
8969
9028
  }
8970
9029
  };
8971
9030
  });
9031
+ /**
9032
+ * Label and helper variants for the text beside the switch. Every size up to `x-large`
9033
+ * follows the shared input map. `xx-large` takes its text from the design system's Toggle
9034
+ * instead, which pairs an 18px SemiBold label with a 16px Regular helper; the shared map
9035
+ * cannot express that, its `xx-large` row being 20px and 18px, and it has no 16px variant
9036
+ * at any size. Only this size's label is SemiBold in the design system, every smaller one
9037
+ * is Regular.
9038
+ *
9039
+ * Text only. The `xx-large` track stays at its own 80x46, not the design system's 64x32,
9040
+ * because `mm-pendant`'s Freedrive toggle renders at this size and shrinking it would
9041
+ * change a touch target.
9042
+ */
9043
+ function getTypographyNames(size) {
9044
+ if (size === "xx-large") {
9045
+ return {
9046
+ labelDiminished: "heading18SemiBold",
9047
+ helperText: "paragraph16Regular"
9048
+ };
9049
+ }
9050
+ return typographyNameFromSizeMap[size];
9051
+ }
8972
9052
  function getThumbSize(theme, size) {
8973
9053
  switch (size) {
8974
9054
  case "small":
8975
9055
  return theme.spacing(2);
8976
- case "medium":
8977
- return theme.spacing(3);
8978
9056
  case "large":
8979
9057
  return theme.spacing(4);
8980
9058
  case "x-large":
@@ -8983,8 +9061,9 @@ function getThumbSize(theme, size) {
8983
9061
  case "xx-large":
8984
9062
  return `calc(${theme.spacing(7)} + 6px)`;
8985
9063
  // 38px
9064
+ case "medium":
8986
9065
  default:
8987
- return getThumbSize(theme, "medium");
9066
+ return theme.spacing(3);
8988
9067
  }
8989
9068
  }
8990
9069
  function getThumbMarginSize(theme, size) {
@@ -9005,11 +9084,6 @@ function getTrackSize(theme, size) {
9005
9084
  // 22px
9006
9085
  height: theme.spacing(3)
9007
9086
  };
9008
- case "medium":
9009
- return {
9010
- width: theme.spacing(6),
9011
- height: theme.spacing(4)
9012
- };
9013
9087
  case "large":
9014
9088
  return {
9015
9089
  width: theme.spacing(7),
@@ -9025,8 +9099,12 @@ function getTrackSize(theme, size) {
9025
9099
  width: theme.spacing(12),
9026
9100
  height: `calc(${theme.spacing(9)} - 2px)`
9027
9101
  };
9102
+ case "medium":
9028
9103
  default:
9029
- return getTrackSize(theme, "medium");
9104
+ return {
9105
+ width: theme.spacing(6),
9106
+ height: theme.spacing(4)
9107
+ };
9030
9108
  }
9031
9109
  }
9032
9110
  function getBackgroundColor$1(theme, checked, variant) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vention/machine-ui",
3
- "version": "5.17.1",
3
+ "version": "5.18.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/VentionCo/machine-cloud.git"
@@ -7,6 +7,8 @@ interface VentionSwitchProps {
7
7
  onChange?: (checked: "on" | "off") => void;
8
8
  disabled?: SwitchProps["disabled"];
9
9
  variant?: Variant;
10
+ labelText?: string;
11
+ helperText?: string;
10
12
  "data-testid"?: string;
11
13
  }
12
14
  export declare const VentionSwitch: (props: VentionSwitchProps) => import("react/jsx-runtime").JSX.Element;
@@ -3,7 +3,7 @@ export type { VentionTagsInputSizes };
3
3
  export interface VentionTagsInputProps {
4
4
  value: string[];
5
5
  onChange: (tags: string[]) => void;
6
- suggestions?: string[];
6
+ suggestions?: readonly string[];
7
7
  label?: string;
8
8
  placeholder?: string;
9
9
  suggestionsTitle?: string;