@icgcat/chart 0.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/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Accordion Component for Svelte
2
+
3
+ ## Introduction
4
+ This Svelte package provides two components for creating collapsible sections: `Accordion` and `SubAccordion`. These components are accessible, customizable, and lightweight, with built-in animations and rich styling options. Perfect for displaying nested or standalone collapsible content sections in a clean and interactive manner.
5
+
6
+ ---
7
+
8
+ ## Installation
9
+
10
+ To clone the package:
11
+
12
+ ```bash
13
+ git clone git@autogitlab.icgc.local:geostarters/components/accordion.git
14
+ ```
15
+
16
+ To install the package, use npm or yarn:
17
+
18
+ ```bash
19
+ npm install @icgcat/accordion
20
+ ```
21
+
22
+ ---
23
+
24
+ ## Usage
25
+
26
+ ### Import and Basic Example
27
+ Here's how to use the `Accordion` and `SubAccordion` components in your Svelte application:
28
+
29
+ ```svelte
30
+ <script>
31
+ import { Accordion, SubAccordion } from "@icgcat/accordion";
32
+
33
+ let openedAccordion = 0; // Track the currently opened accordion
34
+
35
+ const toggleAccordion = (id) => {
36
+ openedAccordion = openedAccordion === id ? 0 : id;
37
+ };
38
+ </script>
39
+
40
+ <Accordion
41
+ id={1}
42
+ openedAccordion={openedAccordion}
43
+ title="First Section"
44
+ iconTheme = "share"
45
+ onToggle={toggleAccordion}
46
+ component={() => <p>Content for the first section</p>}
47
+ />
48
+
49
+ <Accordion
50
+ id={2}
51
+ openedAccordion={openedAccordion}
52
+ title="Second Section"
53
+ iconTheme = "map"
54
+ onToggle={toggleAccordion}
55
+ >
56
+ <SubAccordion
57
+ id={3}
58
+ openedAccordion={openedAccordion}
59
+ title="Nested Section"
60
+ onToggle={toggleAccordion}
61
+ >
62
+ <p>Content for the nested section</p>
63
+ </SubAccordion>
64
+ </Accordion>
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Props
70
+ ### Accordion
71
+ The `Accordion` component accepts the following props:
72
+
73
+ | Prop | Type | Default | Description |
74
+ |-------------------|----------|------------------------|-----------------------------------------------|
75
+ | `id` | `number` | `0` | Unique identifier for each accordion. |
76
+ | `openedAccordion` | `number` | `0` | Tracks the currently opened accordion. |
77
+ | `title` | `string` | `""` | The title displayed in the accordion header. |
78
+ | `className` | `string` | `"acc"` | Custom CSS class for styling. |
79
+ | `iconTheme` | `string` | `"keyboard_arrow_down"` | Icon displayed in the accordion header. |
80
+ | `component` | `any` | `null` | Content rendered inside the accordion body. |
81
+ | `onToggle` | `function` | `null` | Callback triggered when the accordion is toggled. |
82
+ | `openColor` | `string` | `"#FFE448"` | Background color when the accordion is open. |
83
+ | `backgroundColor` | `string` | `"#F5F5F5"` | Default background color. |
84
+ | `hoverColor` | `string` | `"rgb(173, 173, 173)"`| Background color on hover. |
85
+ | `activeColorStyle`| `string` | `"rgb(173, 173, 173)"`| Background color on active state. |
86
+ | `fontColor` | `string` | `"black"` | Font color for the accordion header. |
87
+ | `children` | `function` | `null` | Content passed dynamically to the accordion body. |
88
+
89
+ ### SubAccordion
90
+ The `SubAccordion` component accepts the same props as `Accordion`, with the exception of `component`. Instead, it expects content to be passed as `children`.
91
+
92
+ ---
93
+
94
+ ## Styling
95
+ The components come with default styles, but you can override them using custom CSS. For example:
96
+
97
+ ```css
98
+ .acc {
99
+ border-radius: 8px;
100
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
101
+ }
102
+
103
+ .collapsible-header {
104
+ transition: background-color 0.3s ease;
105
+ }
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Transitions
111
+ These components use Svelte's `slide` transition for smooth opening and closing animations. You can modify or replace the transition if desired.
112
+
113
+ ---
114
+
115
+ ## Accessibility
116
+ - Fully keyboard-navigable.
117
+ - Supports dynamic aria-expanded attributes for screen readers.
118
+
119
+ ---
120
+
121
+ ## Contributions
122
+ Feel free to fork this repository and open pull requests to improve the components or add new features.
123
+
124
+ ---
125
+
126
+ ## License
127
+ This project is licensed under the MIT License.
128
+
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@icgcat/chart",
3
+ "version": "0.0.1",
4
+ "main": "src/index.js",
5
+ "type": "module",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "vite build"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "keywords": [],
14
+ "author": "Geostarters",
15
+ "license": "ISC",
16
+ "description": "A Svelte Chart based on chart.js",
17
+ "devDependencies": {
18
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
19
+ "svelte": "^5.0.0",
20
+ "svelte-preprocess": "^6.0.3",
21
+ "vite": "^6.0.3"
22
+ },
23
+ "dependencies": {
24
+ "chart.js": "^4.4.7"
25
+ }
26
+ }
@@ -0,0 +1,67 @@
1
+ <script>
2
+ import { onMount } from "svelte";
3
+ import Chart from "chart.js/auto";
4
+
5
+ let chartCanvas; // Referència al canvas del gràfic
6
+
7
+ // Configuració inicial del gràfic
8
+ export let chartData = {
9
+ type: "bar", // Tipus de gràfic: bar, line, pie, etc.
10
+ data: {
11
+ labels: [
12
+ "Gener",
13
+ "Febrer",
14
+ "Març",
15
+ "Abril",
16
+ "Maig",
17
+ "Juny",
18
+ "Juliol",
19
+ "Agost",
20
+ "Setembre",
21
+ "Octubre",
22
+ "Novembre",
23
+ "Desembre",
24
+ ],
25
+ datasets: [
26
+ {
27
+ label: "Temperatura mitjana",
28
+ data: [-3, -5, -2, 4, 10, 16, 18, 22, 20, 14, 8, 3],
29
+ backgroundColor: "rgba(75, 192, 192, 0.2)",
30
+ borderColor: "rgba(75, 192, 192, 1)",
31
+ borderWidth: 2,
32
+ },
33
+ ],
34
+ },
35
+ options: {
36
+ responsive: true,
37
+ plugins: {
38
+ legend: {
39
+ display: true,
40
+ position: "bottom",
41
+ },
42
+ },
43
+ },
44
+ };
45
+
46
+ let chartInstance; // Instància del gràfic
47
+
48
+ onMount(() => {
49
+ // Crear el gràfic al muntar el component
50
+ // @ts-ignore
51
+ chartInstance = new Chart(chartCanvas, chartData);
52
+
53
+ return () => {
54
+ // Destruir el gràfic quan es destrueixi el component
55
+ if (chartInstance) chartInstance.destroy();
56
+ };
57
+ });
58
+ </script>
59
+
60
+ <canvas bind:this={chartCanvas}></canvas>
61
+
62
+ <style>
63
+ canvas {
64
+ max-width: 100%;
65
+ margin: 20px 0;
66
+ }
67
+ </style>
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import Chart from "./Chart.svelte";
2
+
3
+ export default Chart;
package/vite.config.js ADDED
@@ -0,0 +1,23 @@
1
+ import { defineConfig } from "vite";
2
+ import { svelte } from "@sveltejs/vite-plugin-svelte";
3
+ import { sveltePreprocess } from "svelte-preprocess";
4
+
5
+ export default defineConfig({
6
+ plugins: [svelte({ preprocess: sveltePreprocess() })],
7
+ build: {
8
+ lib: {
9
+ entry: "src/index.js",
10
+ name: "Chart",
11
+ formats: ["es", "cjs", "umd"],
12
+ fileName: (format) => `svelte-chart.${format}.js`,
13
+ },
14
+ rollupOptions: {
15
+ external: ["svelte"],
16
+ output: {
17
+ globals: {
18
+ svelte: "Svelte",
19
+ },
20
+ },
21
+ },
22
+ },
23
+ });