|
| 1 | +"use client"; |
| 2 | +import { css, cva } from "@styled-system/css"; |
| 3 | +import { Flex } from "@styled-system/jsx"; |
| 4 | +import { Text } from "@wow-class/ui"; |
| 5 | +import clsx from "clsx"; |
| 6 | + |
| 7 | +import GraphToolTip from "./GraphToolTip"; |
| 8 | + |
| 9 | +const BarGraph = ({ |
| 10 | + barColor = "default", |
| 11 | + totalStudent = 0, |
| 12 | + percent = 0, |
| 13 | + isCurriculumCanceled, |
| 14 | + isToolTipActive = true, |
| 15 | +}: { |
| 16 | + barColor?: "default" | "average"; |
| 17 | + totalStudent?: number; |
| 18 | + isToolTipActive?: boolean; |
| 19 | + percent?: number; |
| 20 | + isCurriculumCanceled?: boolean; |
| 21 | +}) => { |
| 22 | + return ( |
| 23 | + <Flex |
| 24 | + alignItems="center" |
| 25 | + flexShrink="0" |
| 26 | + gap="sm" |
| 27 | + justifyContent="flex-start" |
| 28 | + > |
| 29 | + <div |
| 30 | + className={BarGraphBackgroundStyle({ |
| 31 | + type: isCurriculumCanceled ? "canceled" : "default", |
| 32 | + })} |
| 33 | + > |
| 34 | + {percent > 0 ? ( |
| 35 | + <div |
| 36 | + style={{ width: `${50 + (232 - 50) * (percent / 100)}px` }} |
| 37 | + className={clsx( |
| 38 | + barGraphStyle({ |
| 39 | + type: barColor, |
| 40 | + }), |
| 41 | + isToolTipActive && |
| 42 | + css({ |
| 43 | + "&:hover .tooltip": { |
| 44 | + visibility: "visible !important", |
| 45 | + }, |
| 46 | + }) |
| 47 | + )} |
| 48 | + > |
| 49 | + <div className={barGraphInnerStyle}> |
| 50 | + <Text className={percentLabelStyle} color="white" typo="label2"> |
| 51 | + {percent}% |
| 52 | + </Text> |
| 53 | + <GraphToolTip |
| 54 | + studentCount={Math.ceil((percent / 100) * totalStudent)} |
| 55 | + /> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + ) : ( |
| 59 | + <Text className={zeroPercentLabelStyle} color="sub" typo="label2"> |
| 60 | + 0% |
| 61 | + </Text> |
| 62 | + )} |
| 63 | + </div> |
| 64 | + {isCurriculumCanceled && ( |
| 65 | + <Text as="div" color="sub" typo="label2"> |
| 66 | + 휴강 |
| 67 | + </Text> |
| 68 | + )} |
| 69 | + </Flex> |
| 70 | + ); |
| 71 | +}; |
| 72 | + |
| 73 | +export default BarGraph; |
| 74 | + |
| 75 | +const BarGraphBackgroundStyle = cva({ |
| 76 | + base: { |
| 77 | + position: "relative", |
| 78 | + minWidth: "232px", |
| 79 | + width: "232px", |
| 80 | + height: "32px", |
| 81 | + display: "flex", |
| 82 | + alignItems: "center", |
| 83 | + gap: "4px", |
| 84 | + flex: 2, |
| 85 | + zIndex: "5", |
| 86 | + borderRadius: "4px", |
| 87 | + }, |
| 88 | + variants: { |
| 89 | + type: { |
| 90 | + default: { |
| 91 | + backgroundColor: "monoBackgroundPressed", |
| 92 | + }, |
| 93 | + canceled: { |
| 94 | + backgroundColor: "lightDisabled", |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | +}); |
| 99 | + |
| 100 | +const barGraphStyle = cva({ |
| 101 | + base: { |
| 102 | + position: "absolute", |
| 103 | + zIndex: 10, |
| 104 | + top: 0, |
| 105 | + left: 0, |
| 106 | + height: "32px", |
| 107 | + padding: "4px 8px", |
| 108 | + display: "flex", |
| 109 | + alignItems: "center", |
| 110 | + borderRadius: "4px", |
| 111 | + }, |
| 112 | + |
| 113 | + variants: { |
| 114 | + type: { |
| 115 | + default: { |
| 116 | + backgroundColor: "primary", |
| 117 | + }, |
| 118 | + average: { |
| 119 | + backgroundColor: "secondaryYellow", |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | +}); |
| 124 | + |
| 125 | +const percentLabelStyle = css({ |
| 126 | + height: "100%", |
| 127 | + display: "flex", |
| 128 | + alignItems: "center", |
| 129 | +}); |
| 130 | + |
| 131 | +const barGraphInnerStyle = css({ |
| 132 | + position: "relative", |
| 133 | + width: "100%", |
| 134 | + height: "100%", |
| 135 | +}); |
| 136 | + |
| 137 | +const zeroPercentLabelStyle = css({ |
| 138 | + marginLeft: "8px", |
| 139 | +}); |
0 commit comments