{ "translations": { "Auditing / Logging" : "Auditovanie / zaznamenávanie udalostí", "Provides logging abilities for Nextcloud such as logging file accesses or otherwise sensitive actions." : "Poskytuje možnosť zaznamenávania udalostí pre Nextcloud, ako je napríklad prístup k súborom alebo iných citlivých akcií." },"pluralForm" :"nplurals=4; plural=(n % 1 == 0 && n == 1 ? 0 : n % 1 == 0 && n >= 2 && n <= 4 ? 1 : n % 1 != 0 ? 2: 3);" }='header'> cgit logo index : sonarqube.git
Continuous Inspection: https://github.com/SonarSource/sonarqubewww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/design-system/src/components/FacetItem.tsx
blob: 91e258c9f3ea289034e5fe954d4aec94d9ba930f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
 * SonarQube
 * Copyright (C) 2009-2024 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
import styled from '@emotion/styled';
import classNames from 'classnames';
import * as React from 'react';
import tw from 'twin.macro';
import { themeBorder, themeColor, themeContrast } from '../helpers';
import { isDefined } from '../helpers/types';
import { ButtonProps, ButtonSecondary } from '../sonar-aligned/components/buttons';

export type FacetItemProps = Omit<ButtonProps, 'name' | 'onClick'> & {
  active?: boolean;
  /** Disable the item if its value is 0. True by default. */
  disableZero?: boolean;
  name: string | React.ReactNode;
  onClick: (x: string, multiple?: boolean) => void;
  small?: boolean;
  stat?: React.ReactNode;
  statBarPercent?: number;
  /** Textual version of `name` */
  tooltip?: string;
  value: string;
};

const STATBAR_MAX_WIDTH = 60;

export function BaseFacetItem({
  active = false,
  className,
  disabled: disabledProp = false,
  disableZero = true,
  icon,
  name,
  onClick,
  small,
  stat,
  statBarPercent,
  tooltip,
  value,
}: FacetItemProps) {
  // alow an active facet to be disabled even if it now has a "0" stat
  // (it was activated when a different value of My issues/All/New code was selected)
  const disabled = disabledProp || (disableZero && !active && stat !== undefined && stat === 0);

  const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
    event.preventDefault();

    onClick(value, event.ctrlKey || event.metaKey);
  };

  return (
    <StyledItem active={active} className={classNames({ active }, className)} role="listitem">
      <StyledButton
        active={active}
        aria-checked={active}
        aria-label={typeof name === 'string' ? name : undefined}
        data-facet={value}
        disabled={disabled}
        icon={icon}
        onClick={handleClick}
        role="checkbox"
        small={small}
        title={tooltip}
      >
        <div className="container">
          <span className="name">{name}</span>
          <div>
            <span className="stat">{stat}</span>
            {isDefined(statBarPercent) && (
              <FacetStatBar>
                <FacetStatBarInner
                  style={{ '--statBarWidth': `${statBarPercent * STATBAR_MAX_WIDTH}px` }}
                />
              </FacetStatBar>
            )}
          </div>
        </div>
      </StyledButton>
    </StyledItem>
  );
}

BaseFacetItem.displayName = 'FacetItem'; // so that tests don't see the obfuscated production name

export const FacetItem = styled(BaseFacetItem)``;

const StyledButton = styled(ButtonSecondary)<{ active?: boolean; small?: boolean }>`
  ${tw`sw-body-sm`};
  ${tw`sw-box-border`};
  ${tw`sw-h-7`};
  ${tw`sw-px-1`};
  ${tw`sw-rounded-1`};
  ${tw`sw-w-full`};

  ${({ small }) => (small ? tw`sw-body-xs sw-pr-0` : '')};

  --background: ${({ active }) => (active ? themeColor('facetItemSelected') : 'transparent')};
  --backgroundHover: ${({ active }) => (active ? themeColor('facetItemSelected') : 'transparent')};

  --border: none;

  & div.container {
    ${tw`sw-container`};
    ${tw`sw-flex`};
    ${tw`sw-items-center`};
    ${tw`sw-justify-between`};

    & span.name {
      ${tw`sw-pr-1`};
      ${tw`sw-truncate`};

      & mark {
        background-color: ${themeColor('searchHighlight')};
        font-weight: 400;
      }
    }

    & span.stat {
      color: ${themeColor('facetItemLight')};
    }
  }

  &:disabled {
    background-color: transparent;
    border-color: transparent;

    & span.container span.stat {
      color: ${themeContrast('buttonDisabled')};
    }

    &:hover {
      background-color: transparent;
      border-color: transparent;
    }
  }
`;

/*&:hover {
    --border: ${themeBorder('default', 'facetItemSelectedBorder')};
  }*/

const StyledItem = styled.span<{ active: boolean }>`
  border: ${({ active }) =>
    active
      ? themeBorder('default', 'facetItemSelectedBorder')
      : themeBorder('default', 'transparent')};

  border-radius: 0.25rem;

  &:hover,
  &:active,
  &:focus {
    border-color: ${themeColor('facetItemSelectedBorder')};
  }
`;

const FacetStatBar = styled.div`
  ${tw`sw-inline-block`}
  ${tw`sw-ml-2`}

  width: ${STATBAR_MAX_WIDTH}px;
`;

const FacetStatBarInner = styled.div`
  width: var(--statBarWidth);
  min-width: 5px;
  height: 10px;
  background-color: ${themeColor('facetItemGraph')};
  transition: width 0.3s ease;
`;

export const HighlightedFacetItems = styled.div`
  display: flex;
  flex-direction: column;
  width: 100%;

  ${FacetItem} {
    &:is(:hover, .active) {
      border-color: ${themeColor('facetItemSelectedBorder')};
      padding-bottom: 1px;
      border-bottom-width: 0;
      border-bottom-right-radius: 0rem;
      border-bottom-left-radius: 0rem;

      &:last-of-type {
        padding-bottom: 0;
        border-bottom-width: 1px;
        border-radius: 0.25rem;
      }

      & ~ ${FacetItem} {
        border-color: ${themeColor('facetItemSelectedBorder')};
        padding-bottom: 1px;
        padding-top: 1px;
        border-top-width: 0;
        border-bottom-width: 0;
        border-radius: 0;
      }

      & ~ ${FacetItem}:last-of-type {
        padding-bottom: 0;
        border-bottom-width: 1px;
        border-bottom-right-radius: 0.25rem;
        border-bottom-left-radius: 0.25rem;
      }
    }

    &.active {
      background-color: ${themeColor('facetItemSelected')};

      & ~ ${FacetItem} {
        background-color: ${themeColor('facetItemSelected')};
      }

      & ~ ${FacetItem}:hover, & ~ ${FacetItem}:hover ~ ${FacetItem} {
        background-color: ${themeColor('facetItemSelectedHover')};
      }
    }

    &.active ~ ${FacetItem}:hover, &:hover ~ ${FacetItem}.active {
      padding-top: 0;
      border-top-width: 1px;
    }
  }
`;