# tableberg/1.1.5/admin/src/components/ButtonLink.jsx

Tableberg – Simple Gutenberg Table Block, version 1.1.5. 76 lines.

- Page: https://pluginprobe.com/plugins/tableberg/1.1.5/code/admin/src/components/ButtonLink.jsx
- Raw: https://pluginprobe.com/plugins/tableberg/1.1.5/raw/admin/src/components/ButtonLink.jsx
- Modified: 2026-09-16T03:30:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tableberg/1.1.5/code/admin/src/components/ButtonLink.jsx#L10-L20`.

```jsx
import React, { useEffect } from "react";
import ButtonLinkNoUrlError from "../inc/err/ButtonLinkNoUrlError";

/**
 * Button link type.
 *
 * @type {{TEXT: string, PRIMARY: string, DEFAULT: string}}
 */
export const ButtonLinkType = {
    TEXT: "text",
    DEFAULT: "default",
    PRIMARY: "primary",
};

/**
 * Button link component.
 *
 * @param {Object}   props                component properties
 * @param {string}   props.url            target url
 * @param {Function} props.onClickHandler click handler callback, if provided, url direction will be ignored
 * @param {string}   props.type           button link type, should be one of ButtonLinkType object values
 * @param {string}   props.title          button title
 * @class
 */
function ButtonLink({
    title,
    url = null,
    onClickHandler = null,
    type = ButtonLinkType.DEFAULT,
}) {
    /**
     * useEffect hook.
     */
    useEffect(() => {
        if (!url && !onClickHandler) {
            throw new ButtonLinkNoUrlError();
        }
    }, []);

    /**
     * Redirect to component url.
     */
    const redirect = () => {
        window.open(url, "_blank");
    };

    /**
     * Button clicked logic.
     *
     * @param {Event} e click event
     */
    const buttonClicked = e => {
        if (onClickHandler && typeof onClickHandler === "function") {
            onClickHandler(e);
        } else {
            redirect();
        }
    };

    return (
        <div
            className={"tableberg-button-link"}
            data-buttonlink-type={type}
            onClick={buttonClicked}
            role={"button"}
        >
            {title}
        </div>
    );
}

/**
 * @module ButtonLink
 */
export default ButtonLink;

```
