• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8538004962

03 Apr 2024 11:36AM UTC coverage: 18.233% (-3.3%) from 21.535%
8538004962

Pull #528

github

web-flow
Merge c1a248a6f into 45ee7ebb3
Pull Request #528: feat: Kanban view

575 of 1136 branches covered (50.62%)

29 of 2908 new or added lines in 83 files covered. (1.0%)

5 existing lines in 5 files now uncovered.

6439 of 35315 relevant lines covered (18.23%)

3.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/sdk/src/components/editor/rating/Editor.tsx
1
/* eslint-disable @typescript-eslint/naming-convention */
×
NEW
2
import { ColorUtils } from '@teable/core';
×
NEW
3
import type { IRatingFieldOptions } from '@teable/core';
×
4
import { cn } from '@teable/ui-lib';
×
5
import { useState, type FC } from 'react';
×
NEW
6
import { RATING_ICON_MAP } from '../../cell-value';
×
7
import type { ICellEditor } from '../type';
×
8

×
9
interface IRatingEditor extends ICellEditor<number> {
×
10
  options: IRatingFieldOptions;
×
11
  iconClassName?: string;
×
12
}
×
13

×
14
export const RatingEditor: FC<IRatingEditor> = (props) => {
×
15
  const { value, options, readonly, className, iconClassName, onChange } = props;
×
16
  const { icon, color: colorKey, max } = options;
×
17
  const [hoverIndex, setHoverIndex] = useState(-1);
×
18

×
19
  const onChangeInner = (index: number) => {
×
20
    if (readonly) return;
×
21
    const finalValue = index + 1 === value ? undefined : index + 1;
×
22
    onChange?.(finalValue);
×
23
  };
×
24

×
25
  const onHoverIndexChange = (index: number) => {
×
26
    if (readonly) return;
×
27
    setHoverIndex(index);
×
28
  };
×
29

×
30
  const Icon = RATING_ICON_MAP[icon];
×
31
  const color = ColorUtils.getHexForColor(colorKey);
×
32
  const hoveredColor = ColorUtils.getRgbaStringForColor(colorKey, 0.3);
×
33

×
34
  return (
×
35
    <div className={cn('flex items-center h-8', className)}>
×
36
      {Array.from({ length: max }).map((_, index) => {
×
37
        let style = {};
×
38

×
39
        if (value != null && index < value) {
×
40
          style = { fill: color, color };
×
41
        } else if (index <= hoverIndex) {
×
42
          style = { fill: hoveredColor, color: hoveredColor };
×
43
        }
×
44
        return (
×
45
          <Icon
×
46
            key={index}
×
47
            className={cn(
×
48
              'w-6 h-6 mr-2 rounded cursor-pointer text-slate-200 fill-slate-200 dark:text-gray-700 dark:fill-gray-700',
×
49
              iconClassName
×
50
            )}
×
51
            style={style}
×
52
            onMouseEnter={() => onHoverIndexChange(index)}
×
53
            onMouseLeave={() => onHoverIndexChange(-1)}
×
54
            onClick={() => onChangeInner(index)}
×
55
          />
×
56
        );
×
57
      })}
×
58
    </div>
×
59
  );
×
60
};
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc