@react-cupertino-ui/calendar-heatmap 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Anderson Lima
4
+
5
+ This project is inspired by Apple's design principles but is not affiliated with, endorsed, or sponsored by Apple Inc.
6
+
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/dist/index.css ADDED
@@ -0,0 +1,14 @@
1
+ .react-cupertino-ui-calendar-heatmap {
2
+ display: grid;
3
+ grid-template-columns: repeat(auto-fill, minmax(12px, 1fr));
4
+ gap: 0.25rem;
5
+ }
6
+ .react-cupertino-ui-calendar-heatmap .cell {
7
+ width: 12px;
8
+ height: 12px;
9
+ border-radius: 4px;
10
+ background: rgba(15, 23, 42, 0.2);
11
+ }
12
+ .react-cupertino-ui-calendar-heatmap .cell.has-value {
13
+ background: linear-gradient(135deg, #0ea5e9, #6366f1);
14
+ }
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ import type { BaseProps } from "@react-cupertino-ui/shared/lib/interfaces/BaseProps";
3
+ import "./index.scss";
4
+ export interface CalendarHeatmapDatum {
5
+ date: string;
6
+ value: number;
7
+ }
8
+ export interface CalendarHeatmapProps extends Omit<BaseProps<HTMLDivElement>, "children"> {
9
+ data: CalendarHeatmapDatum[];
10
+ weeks?: number;
11
+ }
12
+ declare const CalendarHeatmap: React.ForwardRefExoticComponent<CalendarHeatmapProps & React.RefAttributes<HTMLDivElement>>;
13
+ export { CalendarHeatmap };
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { cn } from "@react-cupertino-ui/shared/lib/utils";
4
+ import "./index.scss";
5
+ const CalendarHeatmap = React.forwardRef((props, ref) => {
6
+ const { className, data, weeks = 8, ...rest } = props;
7
+ const cells = React.useMemo(() => {
8
+ const result = [];
9
+ const today = new Date();
10
+ for (let i = 0; i < weeks * 7; i += 1) {
11
+ const date = new Date(today);
12
+ date.setDate(today.getDate() - (weeks * 7 - i));
13
+ const match = data.find((item) => new Date(item.date).toDateString() === date.toDateString());
14
+ result.push({ date, value: match?.value ?? 0 });
15
+ }
16
+ return result;
17
+ }, [data, weeks]);
18
+ return (_jsx("div", { ref: ref, className: cn("react-cupertino-ui-calendar-heatmap", className), ...rest, children: cells.map((cell, index) => (_jsx("div", { className: cn("cell", cell.value > 0 && "has-value"), style: { opacity: Math.min(1, 0.3 + cell.value * 0.1) } }, `${cell.date.toISOString()}-${index}`))) }));
19
+ });
20
+ CalendarHeatmap.displayName = "CalendarHeatmap";
21
+ export { CalendarHeatmap };
@@ -0,0 +1,16 @@
1
+ .react-cupertino-ui-calendar-heatmap {
2
+ display: grid;
3
+ grid-template-columns: repeat(auto-fill, minmax(12px, 1fr));
4
+ gap: 0.25rem;
5
+
6
+ .cell {
7
+ width: 12px;
8
+ height: 12px;
9
+ border-radius: 4px;
10
+ background: rgba(15, 23, 42, 0.2);
11
+
12
+ &.has-value {
13
+ background: linear-gradient(135deg, #0ea5e9, #6366f1);
14
+ }
15
+ }
16
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@react-cupertino-ui/calendar-heatmap",
3
+ "version": "1.0.1",
4
+ "description": "Calendar heatmap component",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "sideEffects": [
13
+ "./dist/**/*.css",
14
+ "./dist/**/*.scss"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.build.json && npm run build:styles",
18
+ "build:styles": "node ../../../scripts/build-styles.mjs"
19
+ },
20
+ "peerDependencies": {
21
+ "react": "^18.3.1",
22
+ "react-dom": "^18.3.1"
23
+ },
24
+ "dependencies": {
25
+ "@react-cupertino-ui/shared": "workspace:*"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.2.2"
29
+ },
30
+ "gitHead": "3f53987bdb936a331665691b517c2ba9984777f8",
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }