@transferwise/components 0.0.0-experimental-24e63f3 → 0.0.0-experimental-1d9df7f

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/build/index.mjs CHANGED
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import React__default, { forwardRef, useId, cloneElement, useState, useEffect, useRef, useMemo, Component, createContext, useContext, useSyncExternalStore, useCallback, useImperativeHandle, createElement, PureComponent, createRef, isValidElement, Children, Fragment as Fragment$1 } from 'react';
3
3
  import classNames from 'classnames';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
- import { ChevronUp, CrossCircleFill, Cross, Check, Info as Info$1, Alert as Alert$1, ClockBorderless, NavigateAway, Briefcase, Person, ArrowRight, Download, ChevronLeft, ChevronRight, AlertCircleFill, AlertCircle, ArrowLeft, QuestionMarkCircle, Search, CrossCircle, ChevronDown, CheckCircleFill, ClockFill, Upload as Upload$2, Document, Plus, PlusCircle, Bin } from '@transferwise/icons';
5
+ import { ChevronUp, CrossCircleFill, Cross, Check, Info as Info$1, Alert as Alert$1, ClockBorderless, NavigateAway, Briefcase, Person, ArrowRight, Download, ChevronLeft, ChevronRight, AlertCircleFill, CheckCircleFill, ArrowLeft, QuestionMarkCircle, Search, CrossCircle, ChevronDown, ClockFill, Upload as Upload$2, Document, Plus, PlusCircle, Bin } from '@transferwise/icons';
6
6
  import { defineMessages, useIntl, injectIntl, IntlProvider } from 'react-intl';
7
7
  import commonmark from 'commonmark';
8
8
  import { useTheme, ThemeProvider } from '@wise/components-theming';
@@ -4849,12 +4849,29 @@ function InlineAlert({
4849
4849
  className,
4850
4850
  children
4851
4851
  }) {
4852
- const danger = type === 'negative' || type === 'error';
4852
+ const getStatusIcon = sentiment => {
4853
+ // TODO: When `Sentiment.SUCCESS` and `Sentiment.ERROR` will be completely removed from the codebase, we should rewrite this component to StatusIcon using only
4854
+ switch (sentiment) {
4855
+ case Sentiment.POSITIVE:
4856
+ case Sentiment.SUCCESS:
4857
+ return /*#__PURE__*/jsx(CheckCircleFill, {});
4858
+ case Sentiment.WARNING:
4859
+ return /*#__PURE__*/jsx(StatusIcon, {
4860
+ sentiment: sentiment,
4861
+ size: Size.SMALL
4862
+ });
4863
+ case Sentiment.NEGATIVE:
4864
+ case Sentiment.ERROR:
4865
+ return /*#__PURE__*/jsx(CrossCircleFill, {});
4866
+ default:
4867
+ return null;
4868
+ }
4869
+ };
4853
4870
  return /*#__PURE__*/jsxs("div", {
4854
4871
  role: "alert",
4855
4872
  id: id,
4856
- className: classNames('alert alert-detach', `alert-${danger ? 'danger' : type}`, className),
4857
- children: [danger && /*#__PURE__*/jsx(AlertCircle, {}), /*#__PURE__*/jsx("div", {
4873
+ className: classNames('alert alert-detach', `alert-${[Sentiment.NEGATIVE, Sentiment.ERROR].includes(type) ? 'danger' : type}`, className),
4874
+ children: [getStatusIcon(type), /*#__PURE__*/jsx("div", {
4858
4875
  children: children
4859
4876
  })]
4860
4877
  });
@@ -4869,7 +4886,7 @@ const Label = ({
4869
4886
  return /*#__PURE__*/jsx("label", {
4870
4887
  id: id,
4871
4888
  htmlFor: htmlFor,
4872
- className: classNames('control-label d-flex flex-column gap-y-1 m-b-0', className),
4889
+ className: classNames('control-label d-flex flex-column gap-y-xs m-b-0', className),
4873
4890
  children: children
4874
4891
  });
4875
4892
  };
@@ -4877,13 +4894,15 @@ const Label = ({
4877
4894
  const Field = ({
4878
4895
  id,
4879
4896
  label,
4880
- hint,
4881
- error,
4897
+ message: propMessage,
4898
+ type: propType,
4882
4899
  className,
4883
- children
4900
+ children,
4901
+ ...props
4884
4902
  }) => {
4885
- const hasError = Boolean(error);
4886
- const hasHint = Boolean(hint) && !hasError;
4903
+ const type = props.error ? Sentiment.NEGATIVE : propType;
4904
+ const message = props.error || props.hint || propMessage;
4905
+ const hasError = type === Sentiment.NEGATIVE;
4887
4906
  const labelId = useId();
4888
4907
  const fallbackInputId = useId();
4889
4908
  const inputId = id !== null ? id ?? fallbackInputId : undefined;
@@ -4893,26 +4912,24 @@ const Field = ({
4893
4912
  children: /*#__PURE__*/jsx(InputIdContextProvider, {
4894
4913
  value: inputId,
4895
4914
  children: /*#__PURE__*/jsx(InputDescribedByProvider, {
4896
- value: hasError || hasHint ? descriptionId : undefined,
4915
+ value: message ? descriptionId : undefined,
4897
4916
  children: /*#__PURE__*/jsx(InputInvalidProvider, {
4898
4917
  value: hasError,
4899
4918
  children: /*#__PURE__*/jsxs("div", {
4900
4919
  className: classNames('form-group d-block', {
4920
+ 'has-success': type === Sentiment.POSITIVE,
4921
+ 'has-warning': type === Sentiment.WARNING,
4901
4922
  'has-error': hasError,
4902
- 'has-info': hasHint
4923
+ 'has-info': type === Sentiment.NEUTRAL
4903
4924
  }, className),
4904
4925
  children: [/*#__PURE__*/jsxs(Label, {
4905
4926
  id: labelId,
4906
4927
  htmlFor: inputId,
4907
4928
  children: [label, children]
4908
- }), hasHint && /*#__PURE__*/jsx(InlineAlert, {
4909
- type: Sentiment.NEUTRAL,
4929
+ }), message && /*#__PURE__*/jsx(InlineAlert, {
4930
+ type: type,
4910
4931
  id: descriptionId,
4911
- children: hint
4912
- }), hasError && /*#__PURE__*/jsx(InlineAlert, {
4913
- type: Sentiment.NEGATIVE,
4914
- id: descriptionId,
4915
- children: error
4932
+ children: message
4916
4933
  })]
4917
4934
  })
4918
4935
  })