@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
46 lines • 3.26 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Link = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const stylesName_1 = require("../../constants/stylesName/stylesName");
const useManageState_1 = require("../../hooks/useManageState/useManageState");
const useStyles_1 = require("../../hooks/useStyles/useStyles");
const useStylesV2_1 = require("../../hooks/useStyles/useStylesV2");
const genericComponentsProvider_1 = require("../../provider/genericComponents/genericComponentsProvider");
const errorBoundary_1 = require("../../provider/errorBoundary/errorBoundary");
const fallbackComponent_1 = require("../../provider/errorBoundary/fallbackComponent");
const decoration_1 = require("../text/types/decoration");
const disabled_1 = require("./helpers/disabled");
const linkStandAlone_1 = require("./linkStandAlone");
const action_1 = require("./types/action");
const state_1 = require("./types/state");
const LinkComponent = react_1.default.forwardRef(({ action = action_1.LinkActionType.NAVIGATION, decoration = decoration_1.TextDecorationType.AUTO, alignCenter = false, disabled = false, color: colorLinkProp, textVariant, role: roleProp, variant, ctv, ...props }, ref) => {
const { LINK: genericLinkComponent } = (0, genericComponentsProvider_1.useGenericComponents)();
const { role } = (0, disabled_1.disabledLink)(disabled, roleProp);
const ariaDisabled = disabled || undefined;
const actionStyles = (0, useStyles_1.useStyles)(stylesName_1.STYLES_NAME.LINK, action, ctv?.[action]);
const textStyles = (0, useStylesV2_1.useStylesV2)({
styleName: stylesName_1.STYLES_NAME.TEXT,
variantName: textVariant,
isOptional: true,
});
const styles = (variant && actionStyles?.[variant]) || {};
const isInline = action === action_1.LinkActionType.INLINE;
const textDecoration = isInline ? decoration_1.TextDecorationType.UNDERLINE : decoration;
const weight = props.weight || styles.container?.font_weight;
const color = colorLinkProp || styles.font_color || styles.container?.color;
const { state, setRef } = (0, useManageState_1.useManageState)({
states: Object.values(state_1.LinkStateType),
ref,
disabled,
});
return ((0, jsx_runtime_1.jsx)(linkStandAlone_1.LinkStandAlone, { ...props, ref: setRef, action: action, alignCenter: alignCenter, "aria-disabled": ariaDisabled, color: color, component: genericLinkComponent, decoration: textDecoration, role: role, state: state, styles: styles, textStyles: textStyles, weight: weight }));
});
LinkComponent.displayName = 'LinkComponent';
const LinkBoundary = (props, ref) => ((0, jsx_runtime_1.jsx)(errorBoundary_1.ErrorBoundary, { fallBackComponent: (0, jsx_runtime_1.jsx)(fallbackComponent_1.FallbackComponent, { children: (0, jsx_runtime_1.jsx)(linkStandAlone_1.LinkStandAlone, { ...props, ref: ref }) }), children: (0, jsx_runtime_1.jsx)(LinkComponent, { ...props, ref: ref }) }));
exports.Link = react_1.default.forwardRef(LinkBoundary);
//# sourceMappingURL=link.js.map