@julseb-lib/react 0.0.27 → 0.0.30
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/dist/index.cjs.js +927 -905
- package/dist/index.es.js +2657 -2605
- package/dist/index.umd.js +288 -266
- package/dist/lib/components/Avatar/AvatarFunction.tsx +25 -2
- package/dist/lib/components/Avatar/styles.tsx +33 -3
- package/dist/lib/components/Avatar/types.ts +14 -1
- package/dist/lib/components/Image/ImageFunction.tsx +7 -0
- package/dist/lib/components/Image/styles.tsx +25 -1
- package/dist/lib/components/Image/types.ts +7 -0
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import { Image } from "../../"
|
|
|
7
7
|
import { appendStyles } from "../../lib-utils"
|
|
8
8
|
import { LibIcon } from "../LibIcon"
|
|
9
9
|
import type { LibComponentBase } from "../../types"
|
|
10
|
-
import { StyledAvatar } from "./styles"
|
|
10
|
+
import { StyledAvatar, StyledFallback } from "./styles"
|
|
11
11
|
import type { ILibAvatar } from "./types"
|
|
12
12
|
|
|
13
13
|
export const AvatarFunction = forwardRef<
|
|
@@ -28,6 +28,7 @@ export const AvatarFunction = forwardRef<
|
|
|
28
28
|
| "icon"
|
|
29
29
|
| "iconSize"
|
|
30
30
|
| "iconBaseUrl"
|
|
31
|
+
| "fontSize"
|
|
31
32
|
> &
|
|
32
33
|
LibComponentBase<HTMLSpanElement> & {
|
|
33
34
|
hasBadge?: boolean
|
|
@@ -50,6 +51,7 @@ export const AvatarFunction = forwardRef<
|
|
|
50
51
|
icon,
|
|
51
52
|
iconSize,
|
|
52
53
|
iconBaseUrl,
|
|
54
|
+
fontSize = "body",
|
|
53
55
|
...rest
|
|
54
56
|
},
|
|
55
57
|
ref
|
|
@@ -78,6 +80,7 @@ export const AvatarFunction = forwardRef<
|
|
|
78
80
|
$borderRadius={borderRadius}
|
|
79
81
|
$size={size}
|
|
80
82
|
$contentColor={contentColor}
|
|
83
|
+
$fontSize={fontSize}
|
|
81
84
|
{...rest}
|
|
82
85
|
>
|
|
83
86
|
{img && (
|
|
@@ -89,8 +92,28 @@ export const AvatarFunction = forwardRef<
|
|
|
89
92
|
width="100%"
|
|
90
93
|
height="100%"
|
|
91
94
|
fit="cover"
|
|
95
|
+
imgFallback={
|
|
96
|
+
typeof img === "object"
|
|
97
|
+
? { text: img.fallback || "", fontSize }
|
|
98
|
+
: undefined
|
|
99
|
+
}
|
|
92
100
|
fallback={
|
|
93
|
-
typeof img === "object" ?
|
|
101
|
+
typeof img === "object" ? (
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
<StyledFallback
|
|
104
|
+
$backgroundColor={
|
|
105
|
+
img.fallbackBackgroundColor ??
|
|
106
|
+
backgroundColor
|
|
107
|
+
}
|
|
108
|
+
$fontColor={
|
|
109
|
+
img.fallbackFontColor ?? contentColor
|
|
110
|
+
}
|
|
111
|
+
$size={size}
|
|
112
|
+
$fontSize={img.fallbackFontSize ?? fontSize}
|
|
113
|
+
>
|
|
114
|
+
{img.fallback}
|
|
115
|
+
</StyledFallback>
|
|
116
|
+
) : undefined
|
|
94
117
|
}
|
|
95
118
|
/>
|
|
96
119
|
)}
|
|
@@ -2,13 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
import type { FC } from "react"
|
|
4
4
|
import styled, { css } from "styled-components"
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
setDefaultTheme,
|
|
7
|
+
Badge,
|
|
8
|
+
Mixins,
|
|
9
|
+
FONT_WEIGHTS,
|
|
10
|
+
SPACERS,
|
|
11
|
+
stringifyPx,
|
|
12
|
+
} from "../../"
|
|
6
13
|
import type {
|
|
7
14
|
LibAllColors,
|
|
8
15
|
ILibBorder,
|
|
9
16
|
ILibRadius,
|
|
10
17
|
LibSpacers,
|
|
11
18
|
ILibOutline,
|
|
19
|
+
LibFontSizes,
|
|
12
20
|
} from "../../types"
|
|
13
21
|
|
|
14
22
|
const Common = ({
|
|
@@ -52,6 +60,7 @@ const StyledAvatar = styled.span<{
|
|
|
52
60
|
$borderRadius?: ILibRadius
|
|
53
61
|
$backgroundColor: LibAllColors
|
|
54
62
|
$contentColor: LibAllColors
|
|
63
|
+
$fontSize: LibFontSizes
|
|
55
64
|
}>`
|
|
56
65
|
${Common}
|
|
57
66
|
${({ $border }) => Mixins.Border($border)};
|
|
@@ -61,6 +70,7 @@ const StyledAvatar = styled.span<{
|
|
|
61
70
|
font-weight: ${FONT_WEIGHTS.BLACK};
|
|
62
71
|
line-height: var(--avatar-size);
|
|
63
72
|
text-transform: uppercase;
|
|
73
|
+
font-size: ${({ $fontSize }) => Mixins.FontSize($fontSize)};
|
|
64
74
|
`
|
|
65
75
|
|
|
66
76
|
const StyledBadge = styled(Badge)<{
|
|
@@ -82,6 +92,26 @@ const StyledBadge = styled(Badge)<{
|
|
|
82
92
|
}
|
|
83
93
|
` as FC<any>
|
|
84
94
|
|
|
85
|
-
|
|
95
|
+
const StyledFallback = styled.span<{
|
|
96
|
+
$size: number
|
|
97
|
+
$backgroundColor: LibAllColors
|
|
98
|
+
$fontColor: LibAllColors
|
|
99
|
+
$fontSize: LibFontSizes
|
|
100
|
+
}>`
|
|
101
|
+
width: ${({ $size }) => stringifyPx($size)};
|
|
102
|
+
height: ${({ $size }) => stringifyPx($size)};
|
|
103
|
+
font-weight: ${FONT_WEIGHTS.BLACK};
|
|
104
|
+
background-color: ${({ $backgroundColor, theme }) =>
|
|
105
|
+
Mixins.AllColors($backgroundColor, theme)};
|
|
106
|
+
color: ${({ $fontColor, theme }) => Mixins.AllColors($fontColor, theme)};
|
|
107
|
+
font-size: ${({ $fontSize }) => Mixins.FontSize($fontSize)};
|
|
108
|
+
`
|
|
109
|
+
|
|
110
|
+
setDefaultTheme([
|
|
111
|
+
StyledAvatarContainer,
|
|
112
|
+
StyledAvatar,
|
|
113
|
+
StyledBadge,
|
|
114
|
+
StyledFallback,
|
|
115
|
+
])
|
|
86
116
|
|
|
87
|
-
export { StyledAvatarContainer, StyledAvatar, StyledBadge }
|
|
117
|
+
export { StyledAvatarContainer, StyledAvatar, StyledBadge, StyledFallback }
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
ILibPadding,
|
|
10
10
|
LibIcon,
|
|
11
11
|
LibAvatarBadgePosition,
|
|
12
|
+
LibFontSizes,
|
|
12
13
|
} from "../../types"
|
|
13
14
|
|
|
14
15
|
interface ILibAvatarBase extends LibComponentBase<HTMLSpanElement> {
|
|
@@ -18,8 +19,18 @@ interface ILibAvatarBase extends LibComponentBase<HTMLSpanElement> {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
interface AvatarWithImage extends ILibAvatarBase {
|
|
21
|
-
img:
|
|
22
|
+
img:
|
|
23
|
+
| string
|
|
24
|
+
| {
|
|
25
|
+
src: string
|
|
26
|
+
alt: string
|
|
27
|
+
fallback?: string
|
|
28
|
+
fallbackFontSize?: LibFontSizes
|
|
29
|
+
fallbackFontColor?: LibAllColors
|
|
30
|
+
fallbackBackgroundColor?: LibAllColors
|
|
31
|
+
}
|
|
22
32
|
letter?: never
|
|
33
|
+
fontSize?: never
|
|
23
34
|
icon?: never
|
|
24
35
|
iconSize?: never
|
|
25
36
|
iconBaseUrl?: never
|
|
@@ -30,6 +41,7 @@ interface AvatarWithImage extends ILibAvatarBase {
|
|
|
30
41
|
interface AvatarWithLetter extends ILibAvatarBase {
|
|
31
42
|
img?: never
|
|
32
43
|
letter: string
|
|
44
|
+
fontSize?: LibFontSizes
|
|
33
45
|
icon?: never
|
|
34
46
|
iconSize?: never
|
|
35
47
|
iconBaseUrl?: never
|
|
@@ -40,6 +52,7 @@ interface AvatarWithLetter extends ILibAvatarBase {
|
|
|
40
52
|
interface AvatarWithIcon extends ILibAvatarBase {
|
|
41
53
|
img?: never
|
|
42
54
|
letter?: never
|
|
55
|
+
fontSize?: never
|
|
43
56
|
icon: LibIcon
|
|
44
57
|
iconSize?: number
|
|
45
58
|
iconBaseUrl?: string
|
|
@@ -19,6 +19,8 @@ export const ImageFunction = forwardRef<HTMLImageElement, ILibImage>(
|
|
|
19
19
|
height = "auto",
|
|
20
20
|
borderRadius,
|
|
21
21
|
fit,
|
|
22
|
+
loading = "lazy",
|
|
23
|
+
imgFallback,
|
|
22
24
|
...rest
|
|
23
25
|
},
|
|
24
26
|
ref
|
|
@@ -33,11 +35,16 @@ export const ImageFunction = forwardRef<HTMLImageElement, ILibImage>(
|
|
|
33
35
|
ref={ref}
|
|
34
36
|
src={src}
|
|
35
37
|
alt={alt}
|
|
38
|
+
loading={loading}
|
|
39
|
+
data-fallback={imgFallback?.text}
|
|
36
40
|
$aspectRatio={aspectRatio}
|
|
37
41
|
$width={width}
|
|
38
42
|
$height={height}
|
|
39
43
|
$borderRadius={borderRadius}
|
|
40
44
|
$fit={fit}
|
|
45
|
+
$fallbackBackground={imgFallback?.background ?? "primary"}
|
|
46
|
+
$fallbackTextColor={imgFallback?.textColor ?? "background"}
|
|
47
|
+
$fallbackFontSize={imgFallback?.fontSize ?? "body"}
|
|
41
48
|
{...rest}
|
|
42
49
|
/>
|
|
43
50
|
</Suspense>
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
import type { FC } from "react"
|
|
4
4
|
import styled from "styled-components"
|
|
5
5
|
import { stringifyPx } from "@julseb-lib/utils"
|
|
6
|
-
import { setDefaultTheme, Text, Mixins, SPACERS } from "../../"
|
|
6
|
+
import { setDefaultTheme, Text, Mixins, SPACERS, FONT_WEIGHTS } from "../../"
|
|
7
7
|
import type {
|
|
8
8
|
LibAllColors,
|
|
9
9
|
ILibRadius,
|
|
10
10
|
CssObjectFit,
|
|
11
11
|
LibImageBackgroundOverlay,
|
|
12
|
+
LibFontSizes,
|
|
12
13
|
} from "../../types"
|
|
13
14
|
|
|
14
15
|
const StyledImage = styled.img<{
|
|
@@ -17,6 +18,9 @@ const StyledImage = styled.img<{
|
|
|
17
18
|
$borderRadius?: ILibRadius
|
|
18
19
|
$fit?: CssObjectFit
|
|
19
20
|
$aspectRatio?: string
|
|
21
|
+
$fallbackBackground: LibAllColors
|
|
22
|
+
$fallbackTextColor: LibAllColors
|
|
23
|
+
$fallbackFontSize?: LibFontSizes
|
|
20
24
|
}>`
|
|
21
25
|
display: block;
|
|
22
26
|
width: ${({ $width }) => stringifyPx($width)};
|
|
@@ -26,6 +30,26 @@ const StyledImage = styled.img<{
|
|
|
26
30
|
position: relative;
|
|
27
31
|
z-index: 0;
|
|
28
32
|
${({ $borderRadius }) => Mixins.BorderRadius($borderRadius)}
|
|
33
|
+
|
|
34
|
+
&[alt]:after {
|
|
35
|
+
position: absolute;
|
|
36
|
+
top: 0;
|
|
37
|
+
left: 0;
|
|
38
|
+
${Mixins.Flexbox({
|
|
39
|
+
$alignItems: "center",
|
|
40
|
+
$justifyContent: "center",
|
|
41
|
+
})};
|
|
42
|
+
width: 100%;
|
|
43
|
+
height: 100%;
|
|
44
|
+
background-color: ${({ $fallbackBackground, theme }) =>
|
|
45
|
+
Mixins.AllColors($fallbackBackground, theme)};
|
|
46
|
+
color: ${({ $fallbackTextColor, theme }) =>
|
|
47
|
+
Mixins.AllColors($fallbackTextColor, theme)};
|
|
48
|
+
content: attr(data-fallback);
|
|
49
|
+
font-weight: ${FONT_WEIGHTS.BOLD};
|
|
50
|
+
font-size: ${({ $fallbackFontSize }) =>
|
|
51
|
+
Mixins.FontSize($fallbackFontSize)};
|
|
52
|
+
}
|
|
29
53
|
`
|
|
30
54
|
|
|
31
55
|
const ImgContainer = styled.figure<{
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
CssObjectFit,
|
|
8
8
|
LibAllColors,
|
|
9
9
|
LibImageBackgroundOverlay,
|
|
10
|
+
LibFontSizes,
|
|
10
11
|
} from "../../types"
|
|
11
12
|
|
|
12
13
|
interface ILibImageBase
|
|
@@ -16,6 +17,12 @@ interface ILibImageBase
|
|
|
16
17
|
fit?: CssObjectFit
|
|
17
18
|
aspectRatio?: string
|
|
18
19
|
fallback?: JSX.Element | string
|
|
20
|
+
imgFallback?: {
|
|
21
|
+
text: string
|
|
22
|
+
background?: LibAllColors
|
|
23
|
+
textColor?: LibAllColors
|
|
24
|
+
fontSize?: LibFontSizes
|
|
25
|
+
}
|
|
19
26
|
children?: never
|
|
20
27
|
}
|
|
21
28
|
|