Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Gatsby Theme Onegeo
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OneGeo Suite
Libs
Gatsby Theme Onegeo
Commits
eaa23cc6
Commit
eaa23cc6
authored
2 years ago
by
Tojo
Browse files
Options
Downloads
Patches
Plain Diff
carousel
parent
1e1f590a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.d.ts
+10
-0
10 additions, 0 deletions
index.d.ts
index.js
+3
-0
3 additions, 0 deletions
index.js
src/components/core/Carousel.tsx
+73
-44
73 additions, 44 deletions
src/components/core/Carousel.tsx
with
86 additions
and
44 deletions
index.d.ts
+
10
−
0
View file @
eaa23cc6
...
...
@@ -51,6 +51,16 @@ interface LinkProps {
}
export
function
Link
(
props
:
LinkProps
):
JSX
.
Element
;
interface
DataImage
{
src
:
string
;
}
interface
Image
{
images
:
Array
<
DataImage
>
;
isLogo
:
boolean
;
delay
?:
number
;
}
export
function
Carousel
(
props
:
Image
):
JSX
.
Element
;
interface
SearchProps
{}
export
function
Search
(
props
:
SearchProps
):
JSX
.
Element
;
...
...
This diff is collapsed.
Click to expand it.
index.js
+
3
−
0
View file @
eaa23cc6
...
...
@@ -12,3 +12,6 @@ export { default as Search } from "./src/components/core/Search";
// Feature components
export
{
default
as
Hero
}
from
"
./src/components/Hero
"
;
//Carousel components
export
{
default
as
Carousel
}
from
"
./src/components/core/Carousel
"
;
This diff is collapsed.
Click to expand it.
src/components/core/Carousel.tsx
+
73
−
44
View file @
eaa23cc6
import
React
from
"
react
"
;
interface
DataImage
{
id
:
number
src
:
string
src
:
string
;
}
interface
Props
{
images
:
Array
<
DataImage
>
images
:
Array
<
DataImage
>
;
isLogo
:
boolean
;
delay
?:
number
;
}
// const Carousel:React.FC<Props> = ({images}) => {
const
Carousel
=
()
=>
{
const
dataImage
=
[
{
id
:
1
,
src
:
"
https://placeimg.com/800/200/arch
"
,
},
{
id
:
2
,
src
:
"
https://placeimg.com/800/200/arch
"
,
},
{
id
:
3
,
src
:
"
https://placeimg.com/800/200/arch
"
,
},
{
id
:
4
,
src
:
"
https://placeimg.com/800/200/arch
"
,
},
];
const
nbr_image
:
number
=
dataImage
.
length
;
const
Carousel
=
(
props
:
Props
)
=>
{
const
{
images
,
isLogo
,
delay
}
=
props
;
const
[
index
,
setIndex
]
=
React
.
useState
(
1
);
const
nbr_image
:
number
=
images
.
length
;
const
updateIndex
=
(
newIndex
:
number
)
=>
{
if
(
newIndex
<
0
)
{
newIndex
=
nbr_image
-
1
;
}
else
if
(
newIndex
>=
nbr_image
)
{
newIndex
=
0
;
}
setIndex
(
newIndex
);
};
console
.
log
(
"
index
"
,
index
);
React
.
useEffect
(()
=>
{
const
interval
=
setInterval
(()
=>
{
if
(
delay
!=
0
)
{
updateIndex
(
index
+
1
);
}
},
delay
);
return
()
=>
{
if
(
interval
)
{
clearInterval
(
interval
);
}
};
});
return
(
<
div
className
=
"carousel w-full"
>
{
dataImage
.
map
((
item
:
any
,
key
:
any
)
=>
{
return
(
<
div
id
=
{
item
.
id
}
className
=
"carousel-item relative w-full"
key
=
{
key
}
>
<
img
src
=
{
item
.
src
}
className
=
"w-full"
/>
<
div
className
=
"absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2"
>
<
a
href
=
{
(
item
.
id
==
1
)
?
`#
${
nbr_image
}
`
:
`#
${
item
.
id
-
1
}
`
}
className
=
"btn btn-circle"
>
❮
</
a
>
<
a
href
=
{
(
item
.
id
==
nbr_image
)
?
`#1`
:
`#
${
item
.
id
+
1
}
`
}
className
=
"btn btn-circle"
>
❯
</
a
>
</
div
>
<
div
className
=
"carousel w-full truncate"
>
<
div
className
=
"whitespace-nowrap w-full"
style
=
{
{
transform
:
`translateX(-
${
index
*
100
}
%)`
,
transition
:
"
transform 0.3s
"
,
}
}
>
{
images
.
map
((
item
:
any
,
key
:
any
)
=>
{
return
(
<
div
className
=
{
`carousel-item relative w-full inline-block`
}
key
=
{
key
}
>
{
isLogo
?
(
<
div
className
=
"flex justify-center items-center w-full"
>
<
img
src
=
{
item
.
src
}
className
=
"w-56"
/>
</
div
>
)
})
}
)
:
(
<
img
src
=
{
item
.
src
}
className
=
"w-full"
/>
)
}
</
div
>
);
})
}
</
div
>
<
div
className
=
{
`absolute flex justify-between pl-5 pr-5 w-full
${
isLogo
?
"
mt-4
"
:
"
mt-[11rem]
"
}
`
}
>
<
button
onClick
=
{
()
=>
updateIndex
(
index
-
1
)
}
className
=
" bg-[#5A5C68] rounded-3xl w-10 h-10 text-white"
>
❮
</
button
>
<
button
onClick
=
{
()
=>
updateIndex
(
index
+
1
)
}
className
=
" bg-[#5A5C68] rounded-3xl w-10 h-10 text-white"
>
❯
</
button
>
</
div
>
</
div
>
);
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment