-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: New time range label #22317
feat: New time range label #22317
Changes from all commits
4ba0271
945c606
c1d9250
edc5b05
95e473e
d80edd2
de426c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* 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 React, { forwardRef, ReactNode, RefObject } from 'react'; | ||
import { css, styled, useTheme } from '@superset-ui/core'; | ||
import Icons from 'src/components/Icons'; | ||
|
||
export type DateLabelProps = { | ||
label: ReactNode; | ||
isActive?: boolean; | ||
isPlaceholder?: boolean; | ||
onClick?: (event: React.MouseEvent) => void; | ||
}; | ||
|
||
// This is the color that antd components (such as Select or Input) use on hover | ||
// TODO: use theme.colors.primary.base here and in antd components | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just set it as the primary color already? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did initially, but when this component is placed next to antd components (which is the case in the filter bar), you can see the color difference when you hover. We could override antd's border colors on hover, but I'd rather we do it as a separate task since we'd need to take care of many antd components There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Thanks for the context! |
||
const ACTIVE_BORDER_COLOR = '#45BED6'; | ||
|
||
const LabelContainer = styled.div<{ | ||
isActive?: boolean; | ||
isPlaceholder?: boolean; | ||
}>` | ||
${({ theme, isActive, isPlaceholder }) => css` | ||
width: 100%; | ||
height: ${theme.gridUnit * 8}px; | ||
|
||
display: flex; | ||
align-items: center; | ||
flex-wrap: nowrap; | ||
|
||
padding: 0 ${theme.gridUnit * 3}px; | ||
|
||
background-color: ${theme.colors.grayscale.light5}; | ||
|
||
border: 1px solid | ||
${isActive ? ACTIVE_BORDER_COLOR : theme.colors.grayscale.light2}; | ||
border-radius: ${theme.borderRadius}px; | ||
|
||
cursor: pointer; | ||
|
||
transition: border-color 0.3s cubic-bezier(0.65, 0.05, 0.36, 1); | ||
:hover, | ||
:focus { | ||
border-color: ${ACTIVE_BORDER_COLOR}; | ||
} | ||
|
||
.date-label-content { | ||
color: ${isPlaceholder | ||
? theme.colors.grayscale.light1 | ||
: theme.colors.grayscale.dark1}; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
min-width: 0; | ||
flex-shrink: 1; | ||
white-space: nowrap; | ||
} | ||
|
||
span[role='img'] { | ||
margin-left: auto; | ||
padding-left: ${theme.gridUnit}px; | ||
|
||
& > span[role='img'] { | ||
line-height: 0; | ||
} | ||
} | ||
`} | ||
`; | ||
|
||
export const DateLabel = forwardRef( | ||
(props: DateLabelProps, ref: RefObject<HTMLSpanElement>) => { | ||
const theme = useTheme(); | ||
return ( | ||
<LabelContainer {...props} tabIndex={0}> | ||
<span className="date-label-content" ref={ref}> | ||
{props.label} | ||
</span> | ||
<Icons.CalendarOutlined | ||
iconSize="s" | ||
iconColor={theme.colors.grayscale.base} | ||
/> | ||
</LabelContainer> | ||
); | ||
}, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NO_TIME_RANGE
represents a time filter constant, which meansNo filter
in the time filter, so I think the original tooltip title should be kept.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want tooltip to display the label text if label is truncated + the actual time range of it's different than human readable label.
In the case of no filter both the label and the tooltip said "No filter" which was redundant.