@molecule/app-weather-card-react 1.0.0
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 +115 -0
- package/README.md +181 -0
- package/dist/WeatherCard.d.ts +52 -0
- package/dist/WeatherCard.d.ts.map +1 -0
- package/dist/WeatherCard.js +44 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-08-04T00:41:40.523Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/app-weather-card-react
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
`@molecule/app-weather-card-react` — current-conditions hero card.
|
|
16
|
+
Gradient background, glass condition pill, optional alert badge,
|
|
17
|
+
hi/lo chip, and a 24h temperature sparkline rendered from a trace.
|
|
18
|
+
|
|
19
|
+
Stateless about i18n and units: pre-formatted ReactNode labels (eyebrow,
|
|
20
|
+
feelsLikeLabel, highLowLabel, updatedLabel, alertLabel) so the consumer
|
|
21
|
+
owns translation and formatting.
|
|
22
|
+
|
|
23
|
+
Extracted from the weather-dashboard flagship.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { WeatherCard, type WeatherTracePoint } from '@molecule/app-weather-card-react'
|
|
29
|
+
|
|
30
|
+
const hourly: WeatherTracePoint[] = [
|
|
31
|
+
{ hour: '09:00', temperature: 58 },
|
|
32
|
+
{ hour: '12:00', temperature: 64 },
|
|
33
|
+
{ hour: '15:00', temperature: 66 },
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
<WeatherCard
|
|
37
|
+
locationName="San Francisco"
|
|
38
|
+
region="California, USA"
|
|
39
|
+
temperature={62}
|
|
40
|
+
condition="Partly cloudy"
|
|
41
|
+
conditionIcon="partly_cloudy_day"
|
|
42
|
+
eyebrow="Right now"
|
|
43
|
+
feelsLikeLabel="Feels like 60°"
|
|
44
|
+
highLowLabel="H 68° · L 54°"
|
|
45
|
+
updatedLabel="Updated 5m ago"
|
|
46
|
+
alertLevel="watch"
|
|
47
|
+
alertLabel="Heat watch"
|
|
48
|
+
trace={hourly}
|
|
49
|
+
/>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Type
|
|
53
|
+
|
|
54
|
+
`feature`
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install @molecule/app-weather-card-react @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
|
|
60
|
+
npm install -D @types/react
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
### Interfaces
|
|
66
|
+
|
|
67
|
+
#### `WeatherCardProps`
|
|
68
|
+
|
|
69
|
+
Props for the {@link WeatherCard} component.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
interface WeatherCardProps {
|
|
73
|
+
locationName: string
|
|
74
|
+
region?: string | null
|
|
75
|
+
temperature: number
|
|
76
|
+
/** Currently INERT — nothing renders it; pass `feelsLikeLabel` instead. */
|
|
77
|
+
feelsLike?: number | null
|
|
78
|
+
/** Currently INERT — nothing renders it; pass `highLowLabel` instead. */
|
|
79
|
+
high?: number | null
|
|
80
|
+
/** Currently INERT — nothing renders it; pass `highLowLabel` instead. */
|
|
81
|
+
low?: number | null
|
|
82
|
+
condition?: string | null
|
|
83
|
+
/** material-symbols icon name. */
|
|
84
|
+
conditionIcon?: string
|
|
85
|
+
alertLevel?: WeatherAlertLevel | null
|
|
86
|
+
alertLabel?: ReactNode
|
|
87
|
+
/** Pre-formatted relative time string (e.g. "5m ago"). */
|
|
88
|
+
updatedLabel?: ReactNode
|
|
89
|
+
unit?: string
|
|
90
|
+
/** "Right now" eyebrow text — defaults to empty. */
|
|
91
|
+
eyebrow?: ReactNode
|
|
92
|
+
/** 24h trace driving the area sparkline. */
|
|
93
|
+
trace?: ReadonlyArray<WeatherTracePoint>
|
|
94
|
+
/** Pre-formatted "Feels like {N}°" label. */
|
|
95
|
+
feelsLikeLabel?: ReactNode
|
|
96
|
+
/** Pre-formatted high/low chip label. */
|
|
97
|
+
highLowLabel?: ReactNode
|
|
98
|
+
className?: string
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### `WeatherTracePoint`
|
|
103
|
+
|
|
104
|
+
A single hour's temperature measurement in the 24h sparkline trace.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
interface WeatherTracePoint {
|
|
108
|
+
hour: string
|
|
109
|
+
temperature: number
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Types
|
|
114
|
+
|
|
115
|
+
#### `WeatherAlertLevel`
|
|
116
|
+
|
|
117
|
+
Severity level for a weather alert badge.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
type WeatherAlertLevel = 'watch' | 'warning' | 'emergency'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Functions
|
|
124
|
+
|
|
125
|
+
#### `WeatherCard(props)`
|
|
126
|
+
|
|
127
|
+
Atmospheric current-conditions hero.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
function WeatherCard({
|
|
131
|
+
locationName,
|
|
132
|
+
region,
|
|
133
|
+
temperature,
|
|
134
|
+
condition,
|
|
135
|
+
conditionIcon = 'partly_cloudy_day',
|
|
136
|
+
alertLevel,
|
|
137
|
+
alertLabel,
|
|
138
|
+
updatedLabel,
|
|
139
|
+
unit = '°F',
|
|
140
|
+
eyebrow,
|
|
141
|
+
trace,
|
|
142
|
+
feelsLikeLabel,
|
|
143
|
+
highLowLabel,
|
|
144
|
+
className,
|
|
145
|
+
}: WeatherCardProps): ReactElement<unknown, string | JSXElementConstructor<any>>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Injection Notes
|
|
149
|
+
|
|
150
|
+
### Requirements
|
|
151
|
+
|
|
152
|
+
Peer dependencies:
|
|
153
|
+
|
|
154
|
+
- `@molecule/app-react` ^1.0.0
|
|
155
|
+
- `@molecule/app-ui` ^1.0.0
|
|
156
|
+
- `@molecule/app-ui-react` ^1.0.0
|
|
157
|
+
- `react` ^18.0.0 || ^19.0.0
|
|
158
|
+
|
|
159
|
+
### Runtime Dependencies
|
|
160
|
+
|
|
161
|
+
- `@molecule/app-react`
|
|
162
|
+
- `@molecule/app-ui`
|
|
163
|
+
- `@molecule/app-ui-react`
|
|
164
|
+
- `react`
|
|
165
|
+
|
|
166
|
+
The numeric `feelsLike`, `high` and `low` props are currently INERT —
|
|
167
|
+
nothing renders them; only the pre-formatted `feelsLikeLabel` /
|
|
168
|
+
`highLowLabel` strings appear, so always pass the labels. With no
|
|
169
|
+
`trace` (or fewer than 2 points) the sparkline falls back to a fixed
|
|
170
|
+
DECORATIVE path — it looks like data but is fake; pass a real trace or
|
|
171
|
+
hide the card. `conditionIcon` and the alert badge use Material Symbols
|
|
172
|
+
ligature names (host app must load that font). Styling leans on raw
|
|
173
|
+
Tailwind + Material-3 tokens (`from-primary`, `to-tertiary-container`,
|
|
174
|
+
`text-primary-fixed/80`, arbitrary values like `min-h-[360px]`): a
|
|
175
|
+
Tailwind build source-scanning this package's dist plus an M3 theme are
|
|
176
|
+
prerequisites, and text is always white on the gradient. `unit` defaults
|
|
177
|
+
to '°F'; `temperature` is rendered rounded. Props (documented on the
|
|
178
|
+
exported `WeatherCardProps` interface): locationName, region,
|
|
179
|
+
temperature, feelsLike (inert), high (inert), low (inert), condition,
|
|
180
|
+
conditionIcon, alertLevel, alertLabel, updatedLabel, unit, eyebrow,
|
|
181
|
+
trace, feelsLikeLabel, highLowLabel, className.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Current-conditions hero card. Pure presentation — the consumer feeds
|
|
3
|
+
* a location + temperature + optional trace; the component renders the
|
|
4
|
+
* gradient hero, glass condition pill, alert badge, hi/lo chip, and
|
|
5
|
+
* 24h temperature sparkline.
|
|
6
|
+
*
|
|
7
|
+
* Stateless about units and i18n: pass pre-formatted strings if you
|
|
8
|
+
* need anything beyond the default integer-rounded temperature.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
13
|
+
/** Severity level for a weather alert badge. */
|
|
14
|
+
export type WeatherAlertLevel = 'watch' | 'warning' | 'emergency';
|
|
15
|
+
/** A single hour's temperature measurement in the 24h sparkline trace. */
|
|
16
|
+
export interface WeatherTracePoint {
|
|
17
|
+
hour: string;
|
|
18
|
+
temperature: number;
|
|
19
|
+
}
|
|
20
|
+
/** Props for the {@link WeatherCard} component. */
|
|
21
|
+
export interface WeatherCardProps {
|
|
22
|
+
locationName: string;
|
|
23
|
+
region?: string | null;
|
|
24
|
+
temperature: number;
|
|
25
|
+
/** Currently INERT — nothing renders it; pass `feelsLikeLabel` instead. */
|
|
26
|
+
feelsLike?: number | null;
|
|
27
|
+
/** Currently INERT — nothing renders it; pass `highLowLabel` instead. */
|
|
28
|
+
high?: number | null;
|
|
29
|
+
/** Currently INERT — nothing renders it; pass `highLowLabel` instead. */
|
|
30
|
+
low?: number | null;
|
|
31
|
+
condition?: string | null;
|
|
32
|
+
/** material-symbols icon name. */
|
|
33
|
+
conditionIcon?: string;
|
|
34
|
+
alertLevel?: WeatherAlertLevel | null;
|
|
35
|
+
alertLabel?: ReactNode;
|
|
36
|
+
/** Pre-formatted relative time string (e.g. "5m ago"). */
|
|
37
|
+
updatedLabel?: ReactNode;
|
|
38
|
+
unit?: string;
|
|
39
|
+
/** "Right now" eyebrow text — defaults to empty. */
|
|
40
|
+
eyebrow?: ReactNode;
|
|
41
|
+
/** 24h trace driving the area sparkline. */
|
|
42
|
+
trace?: ReadonlyArray<WeatherTracePoint>;
|
|
43
|
+
/** Pre-formatted "Feels like {N}°" label. */
|
|
44
|
+
feelsLikeLabel?: ReactNode;
|
|
45
|
+
/** Pre-formatted high/low chip label. */
|
|
46
|
+
highLowLabel?: ReactNode;
|
|
47
|
+
className?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Atmospheric current-conditions hero. */
|
|
50
|
+
export declare function WeatherCard({ locationName, region, temperature, condition, conditionIcon, alertLevel, alertLabel, updatedLabel, unit, eyebrow, trace, feelsLikeLabel, highLowLabel, className, }: WeatherCardProps): ReactElement;
|
|
51
|
+
export default WeatherCard;
|
|
52
|
+
//# sourceMappingURL=WeatherCard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WeatherCard.d.ts","sourceRoot":"","sources":["../src/WeatherCard.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIpD,gDAAgD;AAChD,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,CAAA;AAEjE,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,mDAAmD;AACnD,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,yEAAyE;IACzE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,kCAAkC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;IACrC,UAAU,CAAC,EAAE,SAAS,CAAA;IACtB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,oDAAoD;IACpD,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;IACxC,6CAA6C;IAC7C,cAAc,CAAC,EAAE,SAAS,CAAA;IAC1B,yCAAyC;IACzC,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAoCD,2CAA2C;AAC3C,wBAAgB,WAAW,CAAC,EAC1B,YAAY,EACZ,MAAM,EACN,WAAW,EACX,SAAS,EACT,aAAmC,EACnC,UAAU,EACV,UAAU,EACV,YAAY,EACZ,IAAW,EACX,OAAO,EACP,KAAK,EACL,cAAc,EACd,YAAY,EACZ,SAAS,GACV,EAAE,gBAAgB,GAAG,YAAY,CAiLjC;AAED,eAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
3
|
+
const ALERT_TONE = {
|
|
4
|
+
watch: 'bg-warning/30 text-white',
|
|
5
|
+
warning: 'bg-error/30 text-white',
|
|
6
|
+
emergency: 'bg-error/60 text-white',
|
|
7
|
+
};
|
|
8
|
+
/** Computes SVG fill and stroke path data for the 24h temperature sparkline. */
|
|
9
|
+
function buildSparkline(trace) {
|
|
10
|
+
const fallback = {
|
|
11
|
+
fill: 'M0,68 Q40,52 80,46 T160,38 T240,55 T320,28 T400,42 L400,100 L0,100 Z',
|
|
12
|
+
stroke: 'M0,68 Q40,52 80,46 T160,38 T240,55 T320,28 T400,42',
|
|
13
|
+
};
|
|
14
|
+
if (!trace || trace.length < 2)
|
|
15
|
+
return fallback;
|
|
16
|
+
const W = 400;
|
|
17
|
+
const H = 100;
|
|
18
|
+
const values = trace.map((p) => p.temperature);
|
|
19
|
+
const min = Math.min(...values);
|
|
20
|
+
const max = Math.max(...values);
|
|
21
|
+
const range = max - min || 1;
|
|
22
|
+
const pts = values.map((v, i) => {
|
|
23
|
+
const x = (i / (values.length - 1)) * W;
|
|
24
|
+
const y = H - ((v - min) / range) * (H * 0.85) - H * 0.1;
|
|
25
|
+
return [x, y];
|
|
26
|
+
});
|
|
27
|
+
const stroke = pts
|
|
28
|
+
.map(([x, y], i) => `${i === 0 ? 'M' : 'L'}${x.toFixed(1)},${y.toFixed(1)}`)
|
|
29
|
+
.join(' ');
|
|
30
|
+
const fill = `${stroke} L${W},${H} L0,${H} Z`;
|
|
31
|
+
return { fill, stroke };
|
|
32
|
+
}
|
|
33
|
+
/** Atmospheric current-conditions hero. */
|
|
34
|
+
export function WeatherCard({ locationName, region, temperature, condition, conditionIcon = 'partly_cloudy_day', alertLevel, alertLabel, updatedLabel, unit = '°F', eyebrow, trace, feelsLikeLabel, highLowLabel, className, }) {
|
|
35
|
+
const cm = getClassMap();
|
|
36
|
+
const sparkline = buildSparkline(trace);
|
|
37
|
+
return (_jsxs("div", { className: cm.cn(cm.flex({ direction: 'col', justify: 'between' }), cm.sp('p', 10), 'min-h-[360px] bg-gradient-to-br from-primary via-primary-container to-tertiary-container rounded-[2rem] text-white relative overflow-hidden shadow-2xl shadow-primary/30', className), children: [_jsxs("div", { className: cm.cn('relative z-10'), children: [_jsxs("div", { className: cm.flex({ align: 'center', justify: 'between', gap: 'md' }), children: [_jsxs("div", { children: [eyebrow ? (_jsx("p", { className: cm.cn(cm.fontWeight('bold'), cm.textSize('xs'), cm.sp('mb', 1), 'uppercase tracking-widest text-primary-fixed/80'), children: eyebrow })) : null, _jsx("h2", { className: cm.cn(cm.textSize('2xl'), cm.fontWeight('semibold'), 'tracking-tight text-white'), children: locationName }), region ? (_jsx("p", { className: cm.cn(cm.textSize('xs'), cm.sp('mt', 1), 'font-mono uppercase tracking-widest text-white/70'), children: region })) : null] }), alertLevel ? (_jsxs("span", { className: cm.cn(cm.flex({ align: 'center', gap: 'xs' }), cm.sp('px', 3), cm.sp('py', 1), cm.roundedFull, cm.fontWeight('bold'), 'text-[10px] uppercase tracking-widest backdrop-blur-md', ALERT_TONE[alertLevel]), children: [_jsx("span", { className: cm.cn('material-symbols-outlined', cm.textSize('sm')), "aria-hidden": "true", children: "warning" }), alertLabel ?? alertLevel] })) : null] }), _jsxs("div", { className: cm.cn(cm.flex({ align: 'baseline', gap: 'lg' }), cm.sp('mt', 8)), children: [_jsxs("span", { className: cm.cn('tabular-nums text-white'), style: {
|
|
38
|
+
fontSize: '4.5rem',
|
|
39
|
+
fontWeight: 200,
|
|
40
|
+
letterSpacing: '-0.03em',
|
|
41
|
+
lineHeight: 1,
|
|
42
|
+
}, children: [Math.round(temperature), unit] }), _jsxs("div", { className: cm.cn(cm.flex({ align: 'center', gap: 'sm' }), cm.sp('px', 3), cm.sp('py', 1), cm.roundedFull, 'bg-white/20 backdrop-blur-md border border-white/15'), children: [_jsx("span", { className: cm.cn('material-symbols-outlined', cm.textSize('2xl')), style: { fontVariationSettings: "'FILL' 1" }, "aria-hidden": "true", children: conditionIcon }), condition ? (_jsx("span", { className: cm.cn(cm.fontWeight('semibold'), cm.textSize('sm')), children: condition })) : null] })] }), _jsxs("div", { className: cm.cn(cm.flex({ align: 'center', gap: 'md', wrap: 'wrap' }), cm.sp('mt', 4)), children: [feelsLikeLabel ? (_jsx("span", { className: cm.cn(cm.textSize('sm'), cm.fontWeight('medium'), 'text-white/85'), children: feelsLikeLabel })) : null, highLowLabel ? (_jsx("span", { className: cm.cn(cm.flex({ align: 'center', gap: 'xs' }), cm.sp('px', 3), cm.sp('py', 1), cm.roundedFull, cm.textSize('xs'), cm.fontWeight('bold'), 'bg-white/15 backdrop-blur-md tabular-nums'), children: highLowLabel })) : null, updatedLabel ? (_jsx("span", { className: cm.cn(cm.textSize('xs'), 'font-mono uppercase tracking-widest text-white/60'), children: updatedLabel })) : null] })] }), _jsx("div", { className: cm.cn(cm.sp('mt', 10), cm.h(24), cm.w('full'), 'relative z-10'), children: _jsxs("svg", { className: cm.cn(cm.w('full'), cm.h('full')), viewBox: "0 0 400 100", preserveAspectRatio: "none", "aria-hidden": "true", children: [_jsx("path", { d: sparkline.fill, fill: "white", opacity: "0.25" }), _jsx("path", { d: sparkline.stroke, fill: "none", stroke: "white", strokeWidth: "2.5", strokeLinecap: "round" })] }) }), _jsx("div", { className: cm.cn('absolute -right-24 -bottom-24 w-72 h-72 rounded-full bg-white/10 blur-3xl'), "aria-hidden": "true" }), _jsx("div", { className: cm.cn('absolute right-12 top-12 w-20 h-20 rounded-full bg-tertiary-fixed/30 blur-2xl'), "aria-hidden": "true" })] }));
|
|
43
|
+
}
|
|
44
|
+
export default WeatherCard;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-weather-card-react` — current-conditions hero card.
|
|
3
|
+
* Gradient background, glass condition pill, optional alert badge,
|
|
4
|
+
* hi/lo chip, and a 24h temperature sparkline rendered from a trace.
|
|
5
|
+
*
|
|
6
|
+
* Stateless about i18n and units: pre-formatted ReactNode labels (eyebrow,
|
|
7
|
+
* feelsLikeLabel, highLowLabel, updatedLabel, alertLabel) so the consumer
|
|
8
|
+
* owns translation and formatting.
|
|
9
|
+
*
|
|
10
|
+
* Extracted from the weather-dashboard flagship.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { WeatherCard, type WeatherTracePoint } from '@molecule/app-weather-card-react'
|
|
15
|
+
*
|
|
16
|
+
* const hourly: WeatherTracePoint[] = [
|
|
17
|
+
* { hour: '09:00', temperature: 58 },
|
|
18
|
+
* { hour: '12:00', temperature: 64 },
|
|
19
|
+
* { hour: '15:00', temperature: 66 },
|
|
20
|
+
* ]
|
|
21
|
+
*
|
|
22
|
+
* <WeatherCard
|
|
23
|
+
* locationName="San Francisco"
|
|
24
|
+
* region="California, USA"
|
|
25
|
+
* temperature={62}
|
|
26
|
+
* condition="Partly cloudy"
|
|
27
|
+
* conditionIcon="partly_cloudy_day"
|
|
28
|
+
* eyebrow="Right now"
|
|
29
|
+
* feelsLikeLabel="Feels like 60°"
|
|
30
|
+
* highLowLabel="H 68° · L 54°"
|
|
31
|
+
* updatedLabel="Updated 5m ago"
|
|
32
|
+
* alertLevel="watch"
|
|
33
|
+
* alertLabel="Heat watch"
|
|
34
|
+
* trace={hourly}
|
|
35
|
+
* />
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* The numeric `feelsLike`, `high` and `low` props are currently INERT —
|
|
40
|
+
* nothing renders them; only the pre-formatted `feelsLikeLabel` /
|
|
41
|
+
* `highLowLabel` strings appear, so always pass the labels. With no
|
|
42
|
+
* `trace` (or fewer than 2 points) the sparkline falls back to a fixed
|
|
43
|
+
* DECORATIVE path — it looks like data but is fake; pass a real trace or
|
|
44
|
+
* hide the card. `conditionIcon` and the alert badge use Material Symbols
|
|
45
|
+
* ligature names (host app must load that font). Styling leans on raw
|
|
46
|
+
* Tailwind + Material-3 tokens (`from-primary`, `to-tertiary-container`,
|
|
47
|
+
* `text-primary-fixed/80`, arbitrary values like `min-h-[360px]`): a
|
|
48
|
+
* Tailwind build source-scanning this package's dist plus an M3 theme are
|
|
49
|
+
* prerequisites, and text is always white on the gradient. `unit` defaults
|
|
50
|
+
* to '°F'; `temperature` is rendered rounded. Props (documented on the
|
|
51
|
+
* exported `WeatherCardProps` interface): locationName, region,
|
|
52
|
+
* temperature, feelsLike (inert), high (inert), low (inert), condition,
|
|
53
|
+
* conditionIcon, alertLevel, alertLabel, updatedLabel, unit, eyebrow,
|
|
54
|
+
* trace, feelsLikeLabel, highLowLabel, className.
|
|
55
|
+
*
|
|
56
|
+
* @module
|
|
57
|
+
*/
|
|
58
|
+
export * from './WeatherCard.js';
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,cAAc,kBAAkB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-weather-card-react` — current-conditions hero card.
|
|
3
|
+
* Gradient background, glass condition pill, optional alert badge,
|
|
4
|
+
* hi/lo chip, and a 24h temperature sparkline rendered from a trace.
|
|
5
|
+
*
|
|
6
|
+
* Stateless about i18n and units: pre-formatted ReactNode labels (eyebrow,
|
|
7
|
+
* feelsLikeLabel, highLowLabel, updatedLabel, alertLabel) so the consumer
|
|
8
|
+
* owns translation and formatting.
|
|
9
|
+
*
|
|
10
|
+
* Extracted from the weather-dashboard flagship.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { WeatherCard, type WeatherTracePoint } from '@molecule/app-weather-card-react'
|
|
15
|
+
*
|
|
16
|
+
* const hourly: WeatherTracePoint[] = [
|
|
17
|
+
* { hour: '09:00', temperature: 58 },
|
|
18
|
+
* { hour: '12:00', temperature: 64 },
|
|
19
|
+
* { hour: '15:00', temperature: 66 },
|
|
20
|
+
* ]
|
|
21
|
+
*
|
|
22
|
+
* <WeatherCard
|
|
23
|
+
* locationName="San Francisco"
|
|
24
|
+
* region="California, USA"
|
|
25
|
+
* temperature={62}
|
|
26
|
+
* condition="Partly cloudy"
|
|
27
|
+
* conditionIcon="partly_cloudy_day"
|
|
28
|
+
* eyebrow="Right now"
|
|
29
|
+
* feelsLikeLabel="Feels like 60°"
|
|
30
|
+
* highLowLabel="H 68° · L 54°"
|
|
31
|
+
* updatedLabel="Updated 5m ago"
|
|
32
|
+
* alertLevel="watch"
|
|
33
|
+
* alertLabel="Heat watch"
|
|
34
|
+
* trace={hourly}
|
|
35
|
+
* />
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* The numeric `feelsLike`, `high` and `low` props are currently INERT —
|
|
40
|
+
* nothing renders them; only the pre-formatted `feelsLikeLabel` /
|
|
41
|
+
* `highLowLabel` strings appear, so always pass the labels. With no
|
|
42
|
+
* `trace` (or fewer than 2 points) the sparkline falls back to a fixed
|
|
43
|
+
* DECORATIVE path — it looks like data but is fake; pass a real trace or
|
|
44
|
+
* hide the card. `conditionIcon` and the alert badge use Material Symbols
|
|
45
|
+
* ligature names (host app must load that font). Styling leans on raw
|
|
46
|
+
* Tailwind + Material-3 tokens (`from-primary`, `to-tertiary-container`,
|
|
47
|
+
* `text-primary-fixed/80`, arbitrary values like `min-h-[360px]`): a
|
|
48
|
+
* Tailwind build source-scanning this package's dist plus an M3 theme are
|
|
49
|
+
* prerequisites, and text is always white on the gradient. `unit` defaults
|
|
50
|
+
* to '°F'; `temperature` is rendered rounded. Props (documented on the
|
|
51
|
+
* exported `WeatherCardProps` interface): locationName, region,
|
|
52
|
+
* temperature, feelsLike (inert), high (inert), low (inert), condition,
|
|
53
|
+
* conditionIcon, alertLevel, alertLabel, updatedLabel, unit, eyebrow,
|
|
54
|
+
* trace, feelsLikeLabel, highLowLabel, className.
|
|
55
|
+
*
|
|
56
|
+
* @module
|
|
57
|
+
*/
|
|
58
|
+
export * from './WeatherCard.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-weather-card-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Atmospheric current-conditions hero card: gradient background, glass condition pill, 24h temperature sparkline, optional alert badge. Extracted from weather-dashboard flagship.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"molecule",
|
|
25
|
+
"weather",
|
|
26
|
+
"card",
|
|
27
|
+
"hero",
|
|
28
|
+
"sparkline",
|
|
29
|
+
"react"
|
|
30
|
+
],
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@molecule/app-react": "^1.0.0",
|
|
34
|
+
"@molecule/app-ui": "^1.0.0",
|
|
35
|
+
"@molecule/app-ui-react": "^1.0.0",
|
|
36
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@molecule/app-react": "1.0.0",
|
|
40
|
+
"@molecule/app-ui": "1.0.0",
|
|
41
|
+
"@molecule/app-ui-react": "1.0.0",
|
|
42
|
+
"@types/node": "26.1.2",
|
|
43
|
+
"@types/react": "19.2.17",
|
|
44
|
+
"react": "19.2.8",
|
|
45
|
+
"typescript": "6.0.3",
|
|
46
|
+
"vitest": "4.1.10"
|
|
47
|
+
}
|
|
48
|
+
}
|