/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import { FC, ReactNode } from 'react'; import { t } from '@apache-superset/core'; import { css, useTheme, SupersetTheme } from '@apache-superset/core/ui'; import { FormLabel, InfoTooltip, Tooltip } from '@superset-ui/core/components'; import { Icons } from '@superset-ui/core/components/Icons'; type ValidationError = string; export type ControlHeaderProps = { name?: string; label?: ReactNode; description?: ReactNode; validationErrors?: ValidationError[]; renderTrigger?: boolean; rightNode?: ReactNode; leftNode?: ReactNode; onClick?: () => void; hovered?: boolean; tooltipOnClick?: () => void; warning?: string; danger?: string; }; const iconStyles = css` &.anticon { font-size: unset; overflow: visible; display: inline-block; vertical-align: middle; line-height: 1; padding-bottom: 0.1em; .anticon { line-height: unset; vertical-align: unset; overflow: visible; } } `; const ControlHeader: FC = ({ name, label, description, validationErrors = [], renderTrigger = false, rightNode, leftNode, onClick, hovered = false, tooltipOnClick = () => {}, warning, danger, }) => { const theme = useTheme(); if (!label) { return null; } const renderOptionalIcons = () => { if (!hovered) { return null; } return ( css` position: absolute; top: 50%; right: 0; padding-left: ${theme.sizeUnit}px; transform: translate(100%, -50%); white-space: nowrap; `} > {description && ( {' '} )} {renderTrigger && ( {' '} )} ); }; return (
css` margin-bottom: ${theme.sizeUnit * 0.5}px; position: relative; font-size: ${theme.fontSizeSM}px; overflow: visible; padding-bottom: 0.1em; `} htmlFor={name} > {leftNode && {leftNode} } {label} {' '} {warning && ( {' '} )} {danger && ( {' '} )} {validationErrors?.length > 0 && ( {' '} )} {renderOptionalIcons()}
{rightNode &&
{rightNode}
}
); }; export default ControlHeader;