Skip to content

Commit 436fa44

Browse files
committed
add styled example
1 parent 24b17c9 commit 436fa44

File tree

18 files changed

+340
-3
lines changed

18 files changed

+340
-3
lines changed

examples/basic-with-apply/src/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const IMAGE_URL = 'landscape.jpg';
77

88
export const App = () => {
99
const [focalPoint, setFocalPoint] = React.useState<FocalPoint>();
10+
1011
return (
1112
<Playground src={IMAGE_URL} focalPoint={focalPoint}>
1213
<ImageFocalPoint src={IMAGE_URL} onChange={setFocalPoint} />

examples/basic-with-apply/src/playground.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ h2 {
5959
gap: 1rem;
6060
width: 100%;
6161
height: 100%;
62-
max-width: 40vw;
6362
}
6463

6564
.portrait-image {

examples/basic/src/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const IMAGE_URL = 'landscape.jpg';
77

88
export const App = () => {
99
const [focalPoint, setFocalPoint] = React.useState<FocalPoint>();
10+
1011
return (
1112
<Playground src={IMAGE_URL} focalPoint={focalPoint}>
1213
<ImageFocalPoint src={IMAGE_URL} onChange={setFocalPoint} />

examples/basic/src/playground.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ h2 {
3636
gap: 1rem;
3737
width: 100%;
3838
height: 100%;
39-
max-width: 40vw;
4039
}
4140

4241
.portrait-image {

examples/controlled/src/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const IMAGE_URL = 'landscape.jpg';
77

88
export const App = () => {
99
const [focalPoint, setFocalPoint] = React.useState<FocalPoint>({ x: 5, y: 10 });
10+
1011
return (
1112
<Playground src={IMAGE_URL} focalPoint={focalPoint}>
1213
<ImageFocalPoint src={IMAGE_URL} focalPoint={focalPoint} onChange={setFocalPoint} />

examples/controlled/src/playground.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ h2 {
3636
gap: 1rem;
3737
width: 100%;
3838
height: 100%;
39-
max-width: 40vw;
4039
}
4140

4241
.portrait-image {

examples/styled/README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Styled
2+
3+
This example shows how to provide styles to the image focal point component.
4+
5+
## How to use
6+
7+
Import the library styles and the component. Use it with minimal properties:
8+
9+
```jsx
10+
import '@lemoncode/react-image-focal-point/style.css';
11+
import { ImageFocalPoint } from '@lemoncode/react-image-focal-point';
12+
13+
const App = () => {
14+
return (
15+
<ImageFocalPoint
16+
src="your-image-src"
17+
onClick={(newFocalPoint) => {
18+
// Whatever you want to do when the user clicks on the image
19+
}}
20+
/>
21+
);
22+
}
23+
24+
```
25+
26+
Create a css file and provide some styles to the root component:
27+
28+
_app.css_
29+
30+
```css
31+
.image-focal-point {
32+
width: 500px;
33+
height: 500px;
34+
}
35+
36+
```
37+
38+
Use it:
39+
40+
```diff
41+
import '@lemoncode/react-image-focal-point/style.css';
42+
import { ImageFocalPoint } from '@lemoncode/react-image-focal-point';
43+
+ import './app.css';
44+
45+
const App = () => {
46+
return (
47+
<ImageFocalPoint
48+
+ className="image-focal-point"
49+
src="your-image-src"
50+
onClick={(newFocalPoint) => {
51+
// Whatever you want to do when the user clicks on the image
52+
}}
53+
/>
54+
);
55+
}
56+
57+
```
58+
59+
You can also provide styles to the image and the focal point:
60+
61+
_app.css_
62+
63+
```diff
64+
.image-focal-point {
65+
width: 500px;
66+
height: 500px;
67+
}
68+
69+
+ .image {
70+
+ border-radius: 10px;
71+
+ }
72+
73+
+ .focal-point {
74+
+ background-color: rgba(255, 0, 0, 0.4);
75+
+ }
76+
77+
```
78+
79+
Use it:
80+
81+
```diff
82+
import '@lemoncode/react-image-focal-point/style.css';
83+
import { ImageFocalPoint } from '@lemoncode/react-image-focal-point';
84+
import './app.css';
85+
86+
const App = () => {
87+
return (
88+
<ImageFocalPoint
89+
- className="image-focal-point"
90+
+ classes={{
91+
+ root: 'image-focal-point',
92+
+ image: 'image',
93+
+ focalPoint: 'focal-point',
94+
+ }}
95+
src="your-image-src"
96+
onClick={(newFocalPoint) => {
97+
// Whatever you want to do when the user clicks on the image
98+
}}
99+
/>
100+
);
101+
}
102+
103+
```
104+
105+
> Note: You can also provide the root styles directly to the classes object instead of using the className prop.
106+
107+
<a target="_blank" href="https://stackblitz.com/github/Lemoncode/react-image-focal-point/tree/main/examples/styled">
108+
<img
109+
src="https://developer.stackblitz.com/img/open_in_stackblitz.svg"
110+
alt="Edit on StackBlitz"
111+
title="Edit on StackBlitz"
112+
height="36"
113+
/>
114+
</a> <a target="_blank" href="https://codesandbox.io/s/github/Lemoncode/react-image-focal-point/tree/main/examples/styled">
115+
<img
116+
src="https://codesandbox.io/static/img/play-codesandbox.svg"
117+
alt="Edit on StackBlitz"
118+
title="Edit on StackBlitz"
119+
height="36"
120+
/>
121+
</a>
122+

examples/styled/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Styled</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/index.tsx"></script>
12+
</body>
13+
</html>

examples/styled/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "styled-example",
3+
"scripts": {
4+
"start": "vite --open"
5+
},
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/Lemoncode/react-image-focal-point.git"
9+
},
10+
"author": "Lemoncode",
11+
"homepage": "https://github.com/Lemoncode/react-image-focal-point/tree/main/#readme",
12+
"devDependencies": {
13+
"@types/react": "^18.0.27",
14+
"@types/react-dom": "^18.0.10",
15+
"@vitejs/plugin-react": "^3.1.0",
16+
"typescript": "^4.9.5",
17+
"vite": "^4.1.1"
18+
},
19+
"dependencies": {
20+
"@lemoncode/react-image-focal-point": "*",
21+
"react": "^18.2.0",
22+
"react-dom": "^18.2.0"
23+
}
24+
}

examples/styled/public/landscape.jpg

2.21 MB
Loading

0 commit comments

Comments
 (0)