@codegouvfr/react-dsfr
Version:
French State Design System React integration library
39 lines • 2.27 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React, { memo, forwardRef } from "react";
import { fr } from "./fr";
import { cx } from "./tools/cx";
import { getLink } from "./link";
import { assert } from "tsafe/assert";
import { symToStr } from "tsafe/symToStr";
/** @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-button> */
export const Button = memo(forwardRef((props, ref) => {
const { className: prop_className, children, title, iconId, iconPosition = "left", priority = "primary", size = "medium", linkProps, onClick, disabled, type } = props, rest = __rest(props, ["className", "children", "title", "iconId", "iconPosition", "priority", "size", "linkProps", "onClick", "disabled", "type"]);
assert();
const { Link } = getLink();
const className = cx(fr.cx("fr-btn", priority !== "primary" &&
`fr-btn--${priority === "tertiary no outline" ? "tertiary-no-outline" : priority}`, size !== "medium" &&
`fr-btn--${(() => {
switch (size) {
case "small":
return "sm";
case "large":
return "lg";
}
})()}`, ...(iconId === undefined
? []
: [iconId, children !== undefined && `fr-btn--icon-${iconPosition}`])), linkProps !== undefined && linkProps.className, prop_className);
return linkProps ? (React.createElement(Link, Object.assign({}, linkProps, { title: title !== null && title !== void 0 ? title : linkProps.title, className: className, ref: ref }, rest), children)) : (React.createElement("button", Object.assign({ className: className, type: type, title: title, onClick: onClick, disabled: disabled, ref: ref }, rest), children));
}));
Button.displayName = symToStr({ Button });
export default Button;
//# sourceMappingURL=Button.js.map