magic-pill 7.1.3 → 8.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.
@@ -82,7 +82,7 @@ html {
82
82
  min-width: max-content;
83
83
  }
84
84
 
85
- >.CTA {
85
+ .CTA {
86
86
  font-family: var(--font-accent);
87
87
  font-size: var(--textSize);
88
88
  font-weight: var(--bold);
@@ -118,7 +118,7 @@ html {
118
118
  }
119
119
  }
120
120
 
121
- >.CTA:hover {
121
+ .CTA:hover {
122
122
  max-width: 300px;
123
123
  }
124
124
 
@@ -141,11 +141,67 @@ html {
141
141
  bottom: 0;
142
142
  height: fit-content !important;
143
143
  transition: height 250ms 0ms ease-in-out, bottom 250ms 0ms ease-in-out, border-radius 250ms 0ms ease-in-out;
144
+
144
145
  >* {
145
146
  opacity: 1;
146
147
  transition: opacity 250ms 250ms ease-in-out;
147
148
  }
148
149
  }
150
+
151
+ >nav.navbar {
152
+ >ul.navbarList {
153
+ display: flex;
154
+ gap: 25px;
155
+ justify-content: space-between;
156
+ list-style: none;
157
+
158
+ >li.navbarItem {
159
+ >a.CTA {
160
+ font-family: var(--font-accent);
161
+ font-size: var(--textSize);
162
+ font-weight: var(--bold);
163
+ display: flex;
164
+ justify-content: flex-start;
165
+ align-items: center;
166
+ gap: 15px;
167
+ padding: 15px;
168
+ max-width: 54.5px;
169
+ min-width: 54.5px;
170
+ overflow: hidden;
171
+ background-color: var(--themeLight);
172
+ color: var(--themeDark);
173
+ text-decoration: none;
174
+ border: transparent;
175
+ border-radius: 100px;
176
+ transition: width 250ms ease-in-out, max-width 250ms ease-in-out, left 250ms ease-in-out, transform 250ms ease-in-out;
177
+ cursor: pointer;
178
+
179
+ >svg {
180
+ min-width: calc(54.5px / 2);
181
+ width: 100%;
182
+ z-index: 1;
183
+ max-width: calc(54.5px / 2);
184
+ }
185
+
186
+ >span {
187
+ z-index: 1;
188
+ min-width: max-content;
189
+ font-family: var(--font-accent);
190
+ color: var(--themeDark);
191
+ text-decoration: none;
192
+ }
193
+ }
194
+ >a.CTA:hover, >a.CTA.active {
195
+ max-width: 300px;
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+
202
+ .magicPill:has(.navbar).out, .magicPill:has(.navbar).entry, .magicPill:has(.navbar).active {
203
+ max-width: 1000px;
204
+ transition: none !important;
149
205
  }
150
206
 
151
207
  .magicPill.active {
@@ -186,10 +242,11 @@ html {
186
242
  p {
187
243
  z-index: -1;
188
244
  }
245
+
189
246
  >button.CTA {
190
247
  position: absolute;
191
- left: 50%;
192
- transform: translateX(-50%);
248
+ left: 50%;
249
+ transform: translateX(-50%);
193
250
  }
194
251
  }
195
252
  }
@@ -0,0 +1,3 @@
1
+ export type { MagicPillNavbar, MagicPillNavbarItem } from './navbar';
2
+ export type { MagicPillNotification, MagicPillNotificationCTA, MagicPillNotificationInfo } from './notification';
3
+ export type { MagicPillType, Mode, NotificationIcon, CTAIcon } from './magicPill';
@@ -0,0 +1,50 @@
1
+ import type { MagicPillNotification } from "./index";
2
+ import type { MagicPillNavbar } from "./index";
3
+ export type Mode = "navbar" | "notification";
4
+ export type NotificationIcon = "info" | "checkmark" | "questionmark" | "coupon" | "";
5
+ export type CTAIcon = "arrow" | "box" | "checkmark" | "cross" | "info" | "mail" | "plus" | "quotation" | "tel" | "undo" | "";
6
+ /**
7
+ * Defines the structure of the Magic Pill component.
8
+ * Magic Pill can be used in two modes:
9
+ * 1. Navbar mode: Displays a navigation bar with multiple items.
10
+ * 2. Notification mode: Displays a notification with an optional call to action (CTA).
11
+ * Each mode has its own specific properties.
12
+ * @see {@link MagicPillNotification} for the structure of the notification.
13
+ * @see {@link MagicPillNavbar} for the structure of the navbar.
14
+ *
15
+ * @example
16
+ * ```json
17
+ * {
18
+ * mode: "navbar",
19
+ * navbar: [
20
+ * { icon: "home", label: "Home", link: "/home" },
21
+ * { icon: "settings", label: "Settings", link: "/settings" }
22
+ * ]
23
+ * }
24
+ * ```
25
+ * @example
26
+ * ```json
27
+ * {
28
+ * mode: "notification",
29
+ * notification: {
30
+ * icon: "info",
31
+ * message: "This is a notification",
32
+ * cta: { icon: "action", label: "Take Action", link: "/action" },
33
+ * info: {
34
+ * title: "Notification Title",
35
+ * content: "This is the content of the notification.",
36
+ * closeLabel: "Close"
37
+ * }
38
+ * }
39
+ * }
40
+ * ```
41
+ */
42
+ export type MagicPillType = {
43
+ mode: "navbar";
44
+ navbar: MagicPillNavbar;
45
+ notification?: never;
46
+ } | {
47
+ mode: "notification";
48
+ notification: MagicPillNotification;
49
+ navbar?: never;
50
+ };
@@ -0,0 +1,27 @@
1
+ import { CTAIcon } from "./index";
2
+ /**
3
+ * Defines the structure of a navigation item in the Magic Pill navbar.
4
+ * Each item has an icon, an optional label, and a link.
5
+ * @example
6
+ * ```ts
7
+ * {
8
+ * icon: "home",
9
+ * label: "Home",
10
+ * link: "/home"
11
+ * }
12
+ * ```
13
+ * @see {@link MagicPillNavbar} for the structure of the navbar that contains these items.
14
+ */
15
+ export interface MagicPillNavbarItem {
16
+ icon: CTAIcon;
17
+ label?: string;
18
+ link: string;
19
+ }
20
+ /**
21
+ * Defines the structure of the navbar in the Magic Pill component.
22
+ * It contains an array of navigation items.
23
+ * @see {@link MagicPillNavbarItem} for the structure of each item in the navbar.
24
+ */
25
+ export interface MagicPillNavbar {
26
+ navItems: MagicPillNavbarItem[];
27
+ }
@@ -0,0 +1,140 @@
1
+ import { NotificationIcon, CTAIcon } from "./index";
2
+ /**
3
+ * Defines the structure of a call to action (CTA) in the Magic Pill notification.
4
+ * Each CTA has an icon, an optional label, and an optional link.
5
+ * @example
6
+ * ```ts
7
+ * {
8
+ * icon: "action",
9
+ * label: "Take Action",
10
+ * link: "/action"
11
+ * }
12
+ * ```
13
+ * @see {@link MagicPillNotification} for the structure of the notification that contains this CTA.
14
+ */
15
+ export interface MagicPillNotificationCTA {
16
+ icon: CTAIcon;
17
+ label?: string;
18
+ link?: string;
19
+ }
20
+ /**
21
+ * Defines the structure of additional information in the Magic Pill notification.
22
+ * This can include a title, content (which can contain HTML), and a close label.
23
+ * @example
24
+ * ```ts
25
+ * {
26
+ * title: "Notification Title",
27
+ * content: "This is the content of the notification.",
28
+ * closeLabel: "Close"
29
+ * }
30
+ * ```
31
+ * @see {@link MagicPillNotification} for the structure of the notification that contains this information.
32
+ * @see {@link MagicPillNotificationCTA} for the structure of the call to action in the notification.
33
+ */
34
+ export interface MagicPillNotificationInfo {
35
+ title?: string;
36
+ content: string;
37
+ closeLabel: string;
38
+ }
39
+ /**
40
+ * Defines the structure of a Magic Pill notification CTA with a link.
41
+ * @example
42
+ * ```ts
43
+ * {
44
+ * icon: "info",
45
+ * label: "Learn More",
46
+ * link: "/learn-more"
47
+ * }
48
+ * ```
49
+ * @see {@link MagicPillNotificationWithLink} for the whole notification structure that incorporates this very type..
50
+ */
51
+ interface MagicPillNotificationCTAWithLink {
52
+ icon: CTAIcon;
53
+ label?: string;
54
+ link: string;
55
+ }
56
+ /**
57
+ * Defines the structure of a Magic Pill notification CTA without a link.
58
+ * @example
59
+ * ```ts
60
+ * {
61
+ * icon: "info",
62
+ * label: "No Link Available"
63
+ * }
64
+ * ```
65
+ * @see {@link MagicPillNotificationWithoutLink} for the whole notification structure that incorporates this very type.
66
+ */
67
+ interface MagicPillNotificationCTAWithoutLink {
68
+ icon: CTAIcon;
69
+ label?: string;
70
+ link?: undefined;
71
+ }
72
+ /**
73
+ * Defines the base structure of a Magic Pill notification.
74
+ * It includes an optional icon and a mandatory message.
75
+ * @example
76
+ * ```ts
77
+ * {
78
+ * icon: "info",
79
+ * message: "This is a notification message."
80
+ * }
81
+ * ```
82
+ * @see {@link MagicPillNotificationWithLink} for notifications that include a CTA with a link.
83
+ * @see {@link MagicPillNotificationWithoutLink} for notifications that include a CTA without a link.
84
+ * @see {@link MagicPillNotificationWithoutCTA} for notifications that do not include a CTA.
85
+ */
86
+ interface MagicPillNotificationBase {
87
+ icon?: NotificationIcon;
88
+ message: string;
89
+ cta?: MagicPillNotificationCTA;
90
+ info?: MagicPillNotificationInfo;
91
+ }
92
+ /**
93
+ * Defines the structure of a Magic Pill notification with a CTA that includes a link.
94
+ * This type extends the base notification structure and includes a CTA with a mandatory link.
95
+ * @example
96
+ * ```ts
97
+ * {
98
+ * icon: "info",
99
+ * message: "This is a notification with a link.",
100
+ * cta: {
101
+ * icon: "action",
102
+ * label: "Take Action",
103
+ * link: "/action"
104
+ * }
105
+ * }
106
+ * ````
107
+ * @see {@link MagicPillNotificationBase} for the base structure of the notification.
108
+ * @see {@link MagicPillNotificationCTAWithLink} for the structure of the CTA with a link.
109
+ */
110
+ type MagicPillNotificationWithLink = MagicPillNotificationBase & {
111
+ cta: MagicPillNotificationCTAWithLink;
112
+ };
113
+ /**
114
+ * Defines the structure of a Magic Pill notification without a link in the CTA.
115
+ * This type extends the base notification structure and includes a CTA without a mandatory link.
116
+ * @example
117
+ * ```ts
118
+ * {
119
+ * icon: "info",
120
+ * message: "This is a notification without a link.",
121
+ * cta: {
122
+ * icon: "action",
123
+ * label: "No Link Available"
124
+ * },
125
+ * info: {
126
+ * title: "Notification Title",
127
+ * content: "This is the content of the notification.",
128
+ * closeLabel: "Close"
129
+ * }
130
+ * }
131
+ * ```
132
+ * @see {@link MagicPillNotificationBase} for the base structure of the notification.
133
+ * @see {@link MagicPillNotificationCTAWithoutLink} for the structure of the CTA without a link.
134
+ */
135
+ type MagicPillNotificationWithoutLink = MagicPillNotificationBase & {
136
+ cta: MagicPillNotificationCTAWithoutLink;
137
+ info: MagicPillNotificationInfo;
138
+ };
139
+ export type MagicPillNotification = MagicPillNotificationWithLink | MagicPillNotificationWithoutLink | MagicPillNotificationBase;
140
+ export {};
@@ -0,0 +1,19 @@
1
+ import { CTAIcon, MagicPillNavbarItem, MagicPillType, Mode, NotificationIcon } from '../types';
2
+ import { SetStateAction, Dispatch } from 'react';
3
+ type SetPillData = Dispatch<SetStateAction<MagicPillType>>;
4
+ export declare const updateMode: (mode: Mode, setPillData: SetPillData) => void;
5
+ export declare const updateNotificationIcon: (icon: NotificationIcon, setPillData: SetPillData) => void;
6
+ export declare const updateNotificationMessage: (message: string, setPillData: SetPillData) => void;
7
+ export declare const updateCTAIcon: (icon: CTAIcon, setPillData: SetPillData) => void;
8
+ export declare const updateCTALabel: (label: string, setPillData: SetPillData) => void;
9
+ export declare const updateCTALink: (link: string, setPillData: SetPillData) => void;
10
+ export declare const updateInfoTitle: (title: string, setPillData: SetPillData) => void;
11
+ export declare const updateInfoContent: (content: string, setPillData: SetPillData) => void;
12
+ export declare const updateInfoCloseLabel: (closeLabel: string, setPillData: SetPillData) => void;
13
+ export declare const updateNavItemLabel: (label: string, index: number, setPillData: SetPillData) => void;
14
+ export declare const updateNavItemLink: (link: string, index: number, setPillData: SetPillData) => void;
15
+ export declare const updateNavItemIcon: (icon: CTAIcon, index: number, setPillData: SetPillData) => void;
16
+ export declare const handleActiveNavItem: (path: string, navItems: MagicPillNavbarItem[]) => string;
17
+ export declare const addNavItem: (navItem: MagicPillNavbarItem, setPillData: SetPillData) => void;
18
+ export declare const deleteNavItem: (index: number, setPillData: SetPillData) => void;
19
+ export {};
@@ -0,0 +1,18 @@
1
+ export declare const Icons: {
2
+ checkmark: () => import("react").JSX.Element;
3
+ coupon: () => import("react").JSX.Element;
4
+ info: () => import("react").JSX.Element;
5
+ questionmark: () => import("react").JSX.Element;
6
+ };
7
+ export declare const CTAIcons: {
8
+ arrow: () => import("react").JSX.Element;
9
+ box: () => import("react").JSX.Element;
10
+ checkmark: () => import("react").JSX.Element;
11
+ cross: () => import("react").JSX.Element;
12
+ mail: () => import("react").JSX.Element;
13
+ plus: () => import("react").JSX.Element;
14
+ quotation: () => import("react").JSX.Element;
15
+ tel: () => import("react").JSX.Element;
16
+ undo: () => import("react").JSX.Element;
17
+ };
18
+ export declare function getIconComponent(iconName: string, iconsMap: Record<string, React.ComponentType<React.SVGProps<SVGSVGElement>>>): import("react").ComponentType<import("react").SVGProps<SVGSVGElement>> | null;
package/package.json CHANGED
@@ -1,42 +1,66 @@
1
1
  {
2
2
  "name": "magic-pill",
3
- "version": "7.1.3",
3
+ "version": "8.0.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.esm.js",
6
- "types": "index.d.ts",
6
+ "types": "dist/index.d.ts",
7
7
  "description": "A new way to guide your audience and bring them contextual information through your app",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/CedricTheveneau/Magic-Pill"
10
+ "url": "git+https://github.com/CedricTheveneau/Magic-Pill.git"
11
11
  },
12
12
  "scripts": {
13
- "build": "rollup -c && cp src/index.d.ts dist/index.d.ts && cp src/magicpill.css dist/magicpill.css",
14
- "prepare": "npm run build"
13
+ "build": "rollup -c && cp src/magicpill.css dist/magicpill.css",
14
+ "prepare": "npm run build",
15
+ "typecheck": "tsc --noEmit"
15
16
  },
16
17
  "peerDependencies": {
17
18
  "next": ">=14.0.0",
18
19
  "react": ">=18.0.0",
19
- "react-dom": ">=18.0.0"
20
+ "react-dom": ">=18.0.0",
21
+ "typescript": ">=5.0.0"
20
22
  },
21
23
  "keywords": [
22
24
  "notifications",
23
25
  "magicpill",
24
- "magic pill"
26
+ "magic pill",
27
+ "navbar",
28
+ "dynamic island",
29
+ "typescript",
30
+ "react",
31
+ "nextjs",
32
+ "ui",
33
+ "component",
34
+ "toast",
35
+ "navigation"
25
36
  ],
26
37
  "author": "Cédric THEVENEAU",
27
38
  "license": "MIT",
39
+ "homepage": "https://github.com/CedricTheveneau/Magic-Pill#readme",
40
+ "bugs": {
41
+ "url": "https://github.com/CedricTheveneau/Magic-Pill/issues"
42
+ },
43
+ "cdn": {
44
+ "url": "https://cdn.jsdelivr.net/npm/magic-pill@latest/dist/index.js",
45
+ "style": "https://cdn.jsdelivr.net/npm/magic-pill@latest/dist/magicpill.css"
46
+ },
28
47
  "devDependencies": {
29
48
  "@babel/core": "^7.26.0",
30
49
  "@babel/preset-env": "^7.26.0",
31
50
  "@babel/preset-react": "^7.25.9",
51
+ "@babel/preset-typescript": "^7.26.0",
32
52
  "@rollup/plugin-babel": "^6.0.4",
53
+ "@rollup/plugin-typescript": "^11.1.6",
54
+ "@types/react": "^18.2.64",
55
+ "@types/react-dom": "^18.2.21",
33
56
  "rollup": "^2.79.2",
34
57
  "rollup-plugin-postcss": "^4.0.2",
35
- "rollup-plugin-terser": "^7.0.2"
58
+ "rollup-plugin-terser": "^7.0.2",
59
+ "tslib": "^2.6.2",
60
+ "typescript": "^5.4.2"
36
61
  },
37
62
  "files": [
38
63
  "dist",
39
- "index.d.ts",
40
64
  "CHANGELOG.md",
41
65
  "LICENSE.md",
42
66
  "NOTICE.md"
package/dist/index.css DELETED
@@ -1 +0,0 @@
1
- @import url("https://fonts.googleapis.com/css2?family=Overlock:ital,wght@0,400;0,700;0,900;1,400;1,700;1,900&display=swap");:root{--themeDark:#141414;--themeLight:#f9f9f9;--font-family:"Overlock",sans-serif;--normal:normal;--italic:italic;--medium:400;--bold:700;--black:900}*,:after,:before{box-sizing:border-box;font-family:var(--font-family);margin:0;padding:0}.magicpill{background-color:var(--themeDark);border-radius:100px;color:var(--themeLight);display:flex;gap:25px;padding:25px}
@@ -1 +0,0 @@
1
- @import url("https://fonts.googleapis.com/css2?family=Overlock:ital,wght@0,400;0,700;0,900;1,400;1,700;1,900&display=swap");:root{--themeDark:#141414;--themeLight:#f9f9f9;--font-family:"Overlock",sans-serif;--normal:normal;--italic:italic;--medium:400;--bold:700;--black:900}*,:after,:before{box-sizing:border-box;font-family:var(--font-family);margin:0;padding:0}.magicpill{background-color:var(--themeDark);border-radius:100px;color:var(--themeLight);display:flex;gap:25px;padding:25px}