@rendr-view/card 0.0.1-alpha.0 → 0.0.1-alpha.2
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 +160 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# @rendr-view/card
|
|
2
|
+
|
|
3
|
+
A base "card" component that displays simple content in a simple structure, intended to be highly customisable to generate a lot of varieties.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn add @rendr-view/card
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
The custom `Btn` props extend the HTML button attributes and HTML anchor link attributes, as well as data and aria attributes.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
export interface Props {
|
|
17
|
+
clx?: object | ClxnLoader;
|
|
18
|
+
className?: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
subtitle?: string;
|
|
21
|
+
text?: string;
|
|
22
|
+
image?: HTMLImageProps;
|
|
23
|
+
buttons?: CardButtonProps[];
|
|
24
|
+
categories?: CardCategory[];
|
|
25
|
+
structure?: CardStructureType;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### clx
|
|
31
|
+
|
|
32
|
+
A record of classNames to style Card elements. The following properties are all optional:
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
buttons?: string;
|
|
36
|
+
button?: string;
|
|
37
|
+
card?: string;
|
|
38
|
+
content?: string;
|
|
39
|
+
categories?: string;
|
|
40
|
+
category?: string;
|
|
41
|
+
figure?: string;
|
|
42
|
+
image?: string;
|
|
43
|
+
imageWrapper?: string;
|
|
44
|
+
paragraph?: string;
|
|
45
|
+
subtitle?: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### className
|
|
50
|
+
|
|
51
|
+
The `className` of the root Card div.
|
|
52
|
+
|
|
53
|
+
### title
|
|
54
|
+
|
|
55
|
+
A title to display.
|
|
56
|
+
|
|
57
|
+
### subtitle
|
|
58
|
+
|
|
59
|
+
A subtitle to display.
|
|
60
|
+
|
|
61
|
+
### text
|
|
62
|
+
|
|
63
|
+
Paragraph text to display.
|
|
64
|
+
|
|
65
|
+
### image
|
|
66
|
+
|
|
67
|
+
An image to display.
|
|
68
|
+
|
|
69
|
+
### buttons
|
|
70
|
+
|
|
71
|
+
An array of CTAs to display (by default will render as `a` links).
|
|
72
|
+
|
|
73
|
+
### categories
|
|
74
|
+
|
|
75
|
+
A list of categories / tags to display (by default will render as a list of `a` links).
|
|
76
|
+
|
|
77
|
+
### structure
|
|
78
|
+
|
|
79
|
+
By default, the card will render the content in a particular structure:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const defaultStructure = [
|
|
83
|
+
"image",
|
|
84
|
+
"categories",
|
|
85
|
+
"title",
|
|
86
|
+
"subtitle",
|
|
87
|
+
"paragraph",
|
|
88
|
+
"buttons"
|
|
89
|
+
];
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
This can be overriden by passing a list of card sections to the `structure` prop.
|
|
93
|
+
|
|
94
|
+
#### Reordering / removing existing sections
|
|
95
|
+
|
|
96
|
+
You can reorder or remove existing sections by simply passing an array of strings that resolve to a particular section. For example:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const slimStructure = [
|
|
100
|
+
"title",
|
|
101
|
+
"image",
|
|
102
|
+
"buttons"
|
|
103
|
+
];
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
This will cause the card to render only the title, image and buttons sections in that order.
|
|
107
|
+
|
|
108
|
+
#### Adding custom components
|
|
109
|
+
|
|
110
|
+
You can add new sections by passing a React component instead of a string. For example:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const customComponentStructure = [
|
|
114
|
+
"title",
|
|
115
|
+
MarkdownTextComponent,
|
|
116
|
+
"buttons"
|
|
117
|
+
]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Custom section components receive `CardSectionProps`, which contains all the props given to the card component plus a `CustomComp` component. This allows you to create custom sections by extending existing sections. Example:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const MyCustomButtons = (props: CardSectionProps) => <CardButtons {...props} CustomComp={Button.Primary} />
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The library exports all the standard sections that can extended in this way:
|
|
127
|
+
|
|
128
|
+
- CardImage
|
|
129
|
+
- CardCategories
|
|
130
|
+
- CardTitle
|
|
131
|
+
- CardSubtitle
|
|
132
|
+
- CardParagraph
|
|
133
|
+
- CardButtons
|
|
134
|
+
|
|
135
|
+
Note, you don't need to extend the standard sections and can pass a completely unique component to render as part of the structure. One advantage of extending the standard sections is that some of the code will have already been written for you: the `clx` classNames will be applied to the elements, list elements will be mapped, and the section will not be rendered if the relevant content is undefined or empty.
|
|
136
|
+
|
|
137
|
+
#### Organising sections into groups
|
|
138
|
+
|
|
139
|
+
By default, sections will be rendered one after the other in the order given in the structure list. If you need finer control over the grouping of sections, you can use `renderCardSectionGroup` function.
|
|
140
|
+
|
|
141
|
+
This function expects two arguments: a className (intended for styling with utility classes), and a structure list:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const imageGroup = renderCardSectionGroup(
|
|
145
|
+
"w-1/2 relative pr-4",
|
|
146
|
+
["image", PriceTagComponent, ImageCaption]
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const textGroup = renderCardSectionGroup(
|
|
150
|
+
"w-1/2 pl-4",
|
|
151
|
+
["title", AvailabilityComponent, "paragraph", "buttons"]
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const myCustomStructure = [
|
|
155
|
+
imageGroup,
|
|
156
|
+
textGroup
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
const CustomCard = (props: Props) => <Card {...props} structure={myCustomStructure} />
|
|
160
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rendr-view/card",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.2",
|
|
4
4
|
"main": "dist/lib/index.js",
|
|
5
5
|
"typing": "dist/lib/index.d.ts",
|
|
6
6
|
"module": "dist/lib-esm/index.js",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"build": "tsc && tsc -m es6 --outDir dist/lib-esm && tsc -m amd --outFile dist/_bundles/card.js"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@rendr-view/with-clxn": "^0.0.1-alpha.
|
|
17
|
+
"@rendr-view/with-clxn": "^0.0.1-alpha.2",
|
|
18
18
|
"clsx": "^1.1.1"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "a3e969b9162f2b3ede0b4190fdc505f4e0c24946"
|
|
21
21
|
}
|