@hyphen/hyphen-components 3.0.0 → 4.0.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/Button/Button.d.ts +12 -51
- package/dist/components/Button/Button.stories.d.ts +1 -1
- package/dist/components/Drawer/Drawer.d.ts +2 -8
- package/dist/components/Sidebar/Sidebar.d.ts +2 -6
- package/dist/css/index.css +1 -1
- package/dist/hyphen-components.cjs.development.js +41 -104
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +1 -1
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +42 -105
- package/dist/hyphen-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Button/Button.mdx +7 -7
- package/src/components/Button/Button.module.scss +3 -0
- package/src/components/Button/Button.stories.tsx +12 -12
- package/src/components/Button/Button.test.tsx +128 -112
- package/src/components/Button/Button.tsx +80 -178
- package/src/components/Drawer/Drawer.tsx +8 -12
- package/src/components/Sidebar/Sidebar.stories.tsx +4 -4
- package/src/lib/tokens.ts +11 -8
|
@@ -3,6 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import React__default, { forwardRef, Children, createElement, cloneElement, useRef, useState, useEffect, isValidElement, useContext, useCallback, useMemo, createContext, useLayoutEffect } from 'react';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import icons from '@hyphen/hyphen-design-tokens/build/assets/icons/react';
|
|
6
|
+
import { Slottable, Slot } from '@radix-ui/react-slot';
|
|
6
7
|
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
|
|
7
8
|
import format from 'date-fns/format';
|
|
8
9
|
import ReactDatePicker from 'react-datepicker';
|
|
@@ -11,7 +12,6 @@ import { usePopper } from 'react-popper';
|
|
|
11
12
|
import FocusTrap from 'focus-trap-react';
|
|
12
13
|
import designTokens from '@hyphen/hyphen-design-tokens/build/json/variables';
|
|
13
14
|
import '@hyphen/hyphen-design-tokens/build/assets/icons';
|
|
14
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
15
15
|
import ReactModal from 'react-modal';
|
|
16
16
|
import FocusLock from 'react-focus-lock';
|
|
17
17
|
import { RemoveScroll } from 'react-remove-scroll';
|
|
@@ -726,99 +726,47 @@ var Spinner = function Spinner(_ref) {
|
|
|
726
726
|
}))));
|
|
727
727
|
};
|
|
728
728
|
|
|
729
|
-
var isModifiedEvent = function isModifiedEvent(e) {
|
|
730
|
-
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
731
|
-
};
|
|
732
|
-
/**
|
|
733
|
-
* Due to react-router's handling of custom components used in RR <Link>
|
|
734
|
-
* we must add this validation that ensures the router will execute the passed `navigate`
|
|
735
|
-
* prop, thus navigating the user without triggering a refresh.
|
|
736
|
-
*
|
|
737
|
-
* SOURCES:
|
|
738
|
-
* https://github.com/ReactTraining/react-router/issues/7727
|
|
739
|
-
* https://github.com/ReactTraining/react-router/issues/7761
|
|
740
|
-
* */
|
|
741
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
742
|
-
var handleReactRouterClick = function handleReactRouterClick(event, onClick, target, navigate) {
|
|
743
|
-
if (onClick) onClick(event);
|
|
744
|
-
if (!event.defaultPrevented &&
|
|
745
|
-
// onClick prevented default
|
|
746
|
-
event.button === 0 && (
|
|
747
|
-
// ignore everything but left clicks
|
|
748
|
-
!target || target === '_self') &&
|
|
749
|
-
// let browser handle "target=_blank" etc.
|
|
750
|
-
!isModifiedEvent(event) &&
|
|
751
|
-
// ignore clicks with modifier keys
|
|
752
|
-
navigate) {
|
|
753
|
-
event.preventDefault();
|
|
754
|
-
navigate();
|
|
755
|
-
}
|
|
756
|
-
};
|
|
757
|
-
|
|
758
729
|
var styles$s = {"button":"Button-module_button__18Bed","size-sm":"Button-module_size-sm__6Xrjw","size-md":"Button-module_size-md__BkuGu","size-lg":"Button-module_size-lg__JVYWV","primary":"Button-module_primary__st6yY","secondary":"Button-module_secondary__j-3rj","tertiary":"Button-module_tertiary__Nd7xM","danger":"Button-module_danger__Hxs5n","size-sm-tablet":"Button-module_size-sm-tablet__9XaSx","size-md-tablet":"Button-module_size-md-tablet__YQxaI","size-lg-tablet":"Button-module_size-lg-tablet__h3l97","size-sm-desktop":"Button-module_size-sm-desktop__8tTsg","size-md-desktop":"Button-module_size-md-desktop__OCdDi","size-lg-desktop":"Button-module_size-lg-desktop__uFc4f","size-sm-hd":"Button-module_size-sm-hd__INFfD","size-md-hd":"Button-module_size-md-hd__8e2mW","size-lg-hd":"Button-module_size-lg-hd__DH60l","loading":"Button-module_loading__QfItr","label":"Button-module_label__1PsXG","full-width":"Button-module_full-width__qDri6","spinner-wrapper":"Button-module_spinner-wrapper__rALNw"};
|
|
759
730
|
|
|
760
|
-
var _excluded$I = ["
|
|
731
|
+
var _excluded$I = ["asChild", "children", "className", "fullWidth", "iconPrefix", "iconSuffix", "isDisabled", "isLoading", "onClick", "onBlur", "onFocus", "shadow", "size", "variant"];
|
|
761
732
|
var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
762
|
-
var _classNames
|
|
763
|
-
var
|
|
764
|
-
children = _ref
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
_ref$iconPrefix = _ref.iconPrefix,
|
|
776
|
-
iconPrefix = _ref$iconPrefix === void 0 ? undefined : _ref$iconPrefix,
|
|
777
|
-
_ref$iconSuffix = _ref.iconSuffix,
|
|
778
|
-
iconSuffix = _ref$iconSuffix === void 0 ? undefined : _ref$iconSuffix,
|
|
779
|
-
_ref$isDisabled = _ref.isDisabled,
|
|
780
|
-
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
|
|
781
|
-
_ref$isLoading = _ref.isLoading,
|
|
782
|
-
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
|
|
783
|
-
_ref$navigate = _ref.navigate,
|
|
784
|
-
navigate = _ref$navigate === void 0 ? undefined : _ref$navigate,
|
|
785
|
-
_ref$onClick = _ref.onClick,
|
|
786
|
-
_onClick = _ref$onClick === void 0 ? undefined : _ref$onClick,
|
|
787
|
-
_ref$onFocus = _ref.onFocus,
|
|
788
|
-
onFocus = _ref$onFocus === void 0 ? undefined : _ref$onFocus,
|
|
789
|
-
_ref$onBlur = _ref.onBlur,
|
|
790
|
-
onBlur = _ref$onBlur === void 0 ? undefined : _ref$onBlur,
|
|
791
|
-
_ref$shadow = _ref.shadow,
|
|
792
|
-
shadow = _ref$shadow === void 0 ? undefined : _ref$shadow,
|
|
733
|
+
var _classNames;
|
|
734
|
+
var asChild = _ref.asChild,
|
|
735
|
+
children = _ref.children,
|
|
736
|
+
className = _ref.className,
|
|
737
|
+
fullWidth = _ref.fullWidth,
|
|
738
|
+
iconPrefix = _ref.iconPrefix,
|
|
739
|
+
iconSuffix = _ref.iconSuffix,
|
|
740
|
+
isDisabled = _ref.isDisabled,
|
|
741
|
+
isLoading = _ref.isLoading,
|
|
742
|
+
onClick = _ref.onClick,
|
|
743
|
+
onBlur = _ref.onBlur,
|
|
744
|
+
onFocus = _ref.onFocus,
|
|
745
|
+
shadow = _ref.shadow,
|
|
793
746
|
_ref$size = _ref.size,
|
|
794
747
|
size = _ref$size === void 0 ? 'md' : _ref$size,
|
|
795
|
-
_ref$tabIndex = _ref.tabIndex,
|
|
796
|
-
tabIndex = _ref$tabIndex === void 0 ? undefined : _ref$tabIndex,
|
|
797
|
-
_ref$target = _ref.target,
|
|
798
|
-
target = _ref$target === void 0 ? undefined : _ref$target,
|
|
799
|
-
_ref$type = _ref.type,
|
|
800
|
-
type = _ref$type === void 0 ? undefined : _ref$type,
|
|
801
748
|
_ref$variant = _ref.variant,
|
|
802
749
|
variant = _ref$variant === void 0 ? 'primary' : _ref$variant,
|
|
803
750
|
restProps = _objectWithoutPropertiesLoose(_ref, _excluded$I);
|
|
804
751
|
var disabled = isLoading || isDisabled;
|
|
805
752
|
var responsiveClasses = generateResponsiveClasses('size', size).map(function (c) {
|
|
806
753
|
return styles$s[c];
|
|
807
|
-
});
|
|
754
|
+
}).filter(Boolean);
|
|
808
755
|
var buttonClasses = classNames('hyphen-components__variables__form-control', styles$s.button, className, responsiveClasses, generateResponsiveClasses('shadow', shadow), (_classNames = {}, _classNames[styles$s.loading] = isLoading, _classNames[styles$s[variant]] = variant, _classNames[styles$s['full-width']] = fullWidth, _classNames));
|
|
809
|
-
var handleClick =
|
|
810
|
-
var
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
756
|
+
var handleClick = !disabled ? onClick : undefined;
|
|
757
|
+
var handleBlur = !disabled ? onBlur : undefined;
|
|
758
|
+
var handleFocus = !disabled ? onFocus : undefined;
|
|
759
|
+
var Comp = asChild ? Slot : 'button';
|
|
760
|
+
return React__default.createElement(Comp, _extends({}, disabled && {
|
|
761
|
+
'aria-disabled': true
|
|
762
|
+
}, {
|
|
763
|
+
disabled: disabled,
|
|
764
|
+
className: buttonClasses,
|
|
765
|
+
onClick: handleClick,
|
|
766
|
+
onBlur: handleBlur,
|
|
767
|
+
onFocus: handleFocus,
|
|
768
|
+
ref: ref
|
|
769
|
+
}, restProps), isLoading && React__default.createElement(Spinner, {
|
|
822
770
|
className: styles$s['spinner-wrapper']
|
|
823
771
|
}), iconPrefix && React__default.createElement(Icon, {
|
|
824
772
|
className: styles$s.label,
|
|
@@ -827,32 +775,18 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
827
775
|
focusable: "false",
|
|
828
776
|
"data-testid": "prefixIcon",
|
|
829
777
|
size: size === 'md' ? 'sm' : size
|
|
830
|
-
}), children && React__default.createElement("span", {
|
|
778
|
+
}), children && React__default.createElement(Slottable, null, asChild ? children : React__default.createElement("span", {
|
|
831
779
|
className: styles$s.label
|
|
832
|
-
}, children), iconSuffix && React__default.createElement(Icon, {
|
|
780
|
+
}, children)), iconSuffix && React__default.createElement(Icon, {
|
|
833
781
|
className: styles$s.label,
|
|
834
782
|
name: iconSuffix,
|
|
835
783
|
"aria-hidden": "true",
|
|
836
784
|
focusable: "false",
|
|
837
785
|
"data-testid": "suffixIcon",
|
|
838
786
|
size: size === 'md' ? 'sm' : size
|
|
839
|
-
}))
|
|
840
|
-
className: styles$s['spinner-wrapper']
|
|
841
|
-
}), function () {
|
|
842
|
-
if (children) {
|
|
843
|
-
return React__default.createElement("span", {
|
|
844
|
-
className: styles$s.label
|
|
845
|
-
}, children);
|
|
846
|
-
}
|
|
847
|
-
return null;
|
|
848
|
-
}());
|
|
849
|
-
var buttonElement = getElementType(Button, {
|
|
850
|
-
as: as
|
|
851
|
-
});
|
|
852
|
-
return createElement(buttonElement, _extends((_extends2 = {}, _extends2['aria-disabled'] = disabled, _extends2.id = id, _extends2.href = href, _extends2.className = buttonClasses, _extends2.disabled = disabled, _extends2.target = as === 'a' && href ? target : null, _extends2.rel = as === 'a' && href && target === '_blank' ? 'noopener noreferrer' : null, _extends2.onBlur = handleBlur, _extends2.onClick = function onClick(event) {
|
|
853
|
-
return handleClick(event, _onClick, target, navigate);
|
|
854
|
-
}, _extends2.onFocus = handleFocus, _extends2.ref = ref, _extends2.type = type || (as !== 'a' && !href ? 'button' : undefined), _extends2.tabIndex = tabIndex, _extends2), restProps), buttonContent);
|
|
787
|
+
}));
|
|
855
788
|
});
|
|
789
|
+
Button.displayName = 'Button';
|
|
856
790
|
|
|
857
791
|
var _excluded$H = ["background", "borderColor", "borderWidth", "children", "display", "padding"];
|
|
858
792
|
var CardFooter = function CardFooter(_ref) {
|
|
@@ -1587,6 +1521,9 @@ var BREAKPOINTS = /*#__PURE__*/[].concat(Object.entries(designTokens.size.breakp
|
|
|
1587
1521
|
minWidth: parseInt(data['value'], 10)
|
|
1588
1522
|
};
|
|
1589
1523
|
}
|
|
1524
|
+
return undefined;
|
|
1525
|
+
}).filter(function (breakpoint) {
|
|
1526
|
+
return breakpoint !== undefined;
|
|
1590
1527
|
});
|
|
1591
1528
|
var Z_INDEX_VALUES = designTokens.size['z-index'];
|
|
1592
1529
|
// export const BOX_SHADOW_VALUES = designTokens.size['box-shadow'];
|
|
@@ -2093,11 +2030,11 @@ var DrawerTitle = /*#__PURE__*/React__default.forwardRef(function (_ref5, ref) {
|
|
|
2093
2030
|
fontWeight: "bold"
|
|
2094
2031
|
}, props));
|
|
2095
2032
|
});
|
|
2096
|
-
var DrawerCloseButton = /*#__PURE__*/
|
|
2033
|
+
var DrawerCloseButton = /*#__PURE__*/forwardRef(function (_ref6, ref) {
|
|
2097
2034
|
var className = _ref6.className,
|
|
2098
2035
|
onClick = _ref6.onClick,
|
|
2099
2036
|
onClose = _ref6.onClose,
|
|
2100
|
-
|
|
2037
|
+
rest = _objectWithoutPropertiesLoose(_ref6, _excluded4$2);
|
|
2101
2038
|
var context = useContext(DrawerContext);
|
|
2102
2039
|
var isStandalone = !context;
|
|
2103
2040
|
var handleClick = function handleClick(event) {
|
|
@@ -2111,7 +2048,6 @@ var DrawerCloseButton = /*#__PURE__*/React__default.forwardRef(function (_ref6,
|
|
|
2111
2048
|
}
|
|
2112
2049
|
};
|
|
2113
2050
|
return React__default.createElement(Button, _extends({
|
|
2114
|
-
ref: ref,
|
|
2115
2051
|
variant: "tertiary",
|
|
2116
2052
|
"aria-label": "close",
|
|
2117
2053
|
type: "button",
|
|
@@ -2119,8 +2055,9 @@ var DrawerCloseButton = /*#__PURE__*/React__default.forwardRef(function (_ref6,
|
|
|
2119
2055
|
"data-drawer": "close",
|
|
2120
2056
|
className: classNames('m-left-auto', className),
|
|
2121
2057
|
size: "sm",
|
|
2122
|
-
onClick: handleClick
|
|
2123
|
-
|
|
2058
|
+
onClick: handleClick,
|
|
2059
|
+
ref: ref
|
|
2060
|
+
}, rest));
|
|
2124
2061
|
});
|
|
2125
2062
|
DrawerCloseButton.displayName = 'DrawerCloseButton';
|
|
2126
2063
|
var DrawerContent = /*#__PURE__*/React__default.forwardRef(function (_ref7, ref) {
|