-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from grucloud/Product-preview-card
product preview card
- Loading branch information
Showing
15 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
save-exact = true | ||
package-lock = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Frontend Mentor Product Preview Card | ||
|
||
Here is the implementation in [Bau.js](https://github.com/grucloud/bau) of the [Frontend Mentor Product Preview Card code challenge](https://www.frontendmentor.io/challenges/product-preview-card-component-GO7UmttRfa/hub) | ||
|
||
## Workflow | ||
|
||
Install the dependencies: | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
Start a development server: | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
Build a production version: | ||
|
||
```sh | ||
npm run build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link | ||
rel="icon" | ||
type="image/png" | ||
href="./assets/images/favicon-32x32.png" | ||
/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Product Preview Card | FrontendMentor</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "frontendmentor-product-preview-card", | ||
"private": true, | ||
"version": "0.85.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.0.2", | ||
"vite": "^5.2.11" | ||
}, | ||
"dependencies": { | ||
"@grucloud/bau": "^0.85.0", | ||
"@grucloud/bau-css": "^0.85.0", | ||
"@grucloud/bau-ui": "^0.85.0" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
examples/product-preview-card/public/assets/images/icon-cart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44 KB
examples/product-preview-card/public/assets/images/image-product-desktop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.8 KB
examples/product-preview-card/public/assets/images/image-product-mobile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createContext, type Context } from "@grucloud/bau-ui/context"; | ||
import productPreviewCard from "./productPreviewCard"; | ||
|
||
import "./style.css"; | ||
|
||
const context = createContext(); | ||
|
||
const app = (context: Context) => { | ||
const { bau } = context; | ||
const { main } = bau.tags; | ||
|
||
const ProductPreviewCard = productPreviewCard(context); | ||
|
||
return function () { | ||
return main(ProductPreviewCard()); | ||
}; | ||
}; | ||
|
||
const App = app(context); | ||
document.getElementById("app")?.replaceChildren(App()); |
116 changes: 116 additions & 0 deletions
116
examples/product-preview-card/src/productPreviewCard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { type Context } from "@grucloud/bau-ui/context"; | ||
|
||
export default function (context: Context) { | ||
const { bau, css } = context; | ||
const { h1, div, p, article, section, img, picture, source, span, button } = | ||
bau.tags; | ||
|
||
const className = css` | ||
display: grid; | ||
margin: 1rem; | ||
grid-template-columns: 350px 350px; | ||
grid-template-rows: 1fr; | ||
@media (max-width: 475px) { | ||
grid-template-columns: 1fr; | ||
grid-template-rows: auto 1fr; | ||
} | ||
picture { | ||
img { | ||
display: block; | ||
width: 100%; | ||
border-radius: 1rem 0 0 1rem; | ||
@media (max-width: 475px) { | ||
border-radius: 1rem; | ||
} | ||
} | ||
} | ||
.content { | ||
background-color: white; | ||
border-radius: 0 1rem 1rem 0; | ||
padding: 1rem; | ||
gap: 0.5rem; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-around; | ||
.category { | ||
letter-spacing: 0.3rem; | ||
text-transform: uppercase; | ||
font-weight: 500; | ||
color: var(--paragraph-color); | ||
font-size: 1rem; | ||
} | ||
h1 { | ||
font-family: "Fraunces", sans-serif; | ||
font-size: 2rem; | ||
} | ||
p { | ||
color: var(--paragraph-color); | ||
} | ||
.price-container { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: 1rem; | ||
.price { | ||
font-family: "Fraunces", sans-serif; | ||
color: var(--btn-and-current-price-color); | ||
font-size: 2rem; | ||
} | ||
.price-old { | ||
font-size: 1rem; | ||
color: var(--paragraph-color); | ||
text-decoration: line-through; | ||
} | ||
} | ||
button { | ||
width: 100%; | ||
border-radius: 1rem; | ||
background-color: var(--btn-and-current-price-color); | ||
color: white; | ||
border: none; | ||
font-weight: 700; | ||
padding: 0.8rem; | ||
display: inline-flex; | ||
gap: 0.4rem; | ||
justify-content: center; | ||
cursor: pointer; | ||
transition: background-color 0.5s; | ||
&::before { | ||
content: url("./assets/images/icon-cart.svg"); | ||
} | ||
&:hover { | ||
background-color: var(--hover-color); | ||
} | ||
} | ||
} | ||
`; | ||
|
||
return function myComponent() { | ||
return article( | ||
{ class: className }, | ||
picture( | ||
source({ | ||
srcset: "./assets/images/image-product-desktop.jpg", | ||
media: "(min-width:476px)", | ||
}), | ||
img({ src: "./assets/images/image-product-mobile.jpg", alt: "Mobile" }) | ||
), | ||
// img({ src: "./assets/images/image-product-desktop.jpg", alt: "Mobile" }), | ||
section( | ||
{ class: "content" }, | ||
div({ class: "category" }, "Perfume"), | ||
h1("Gabrielle Essence Eau De Parfum"), | ||
p( | ||
"A floral, solar and voluptuous interpretation composed by Olivier Polge, Perfumer-Creator for the House of CHANEL." | ||
), | ||
div( | ||
{ class: "price-container" }, | ||
span({ class: "price" }, "$149.99"), | ||
span({ class: "price-old" }, "$169.99") | ||
), | ||
button("Add to Cart") | ||
) | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@import url("https://fonts.googleapis.com/css2?family=Fraunces:wght@700&family=Montserrat:wght@500;700&display=swap"); | ||
|
||
* { | ||
margin: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
:root { | ||
--btn-and-current-price-color: hsl(158, 36%, 37%); | ||
--product-title-color: hsl(212, 21%, 14%); | ||
--paragraph-color: hsl(228, 12%, 48%); | ||
--card-color: hsl(0, 0%, 100%); | ||
--hover-color: hsl(157, 46%, 17%); | ||
} | ||
|
||
body { | ||
--background-color: hsl(30, 38%, 92%); | ||
font-family: "Montserrat", sans-serif; | ||
min-height: 100vh; | ||
background-color: var(--background-color); | ||
display: grid; | ||
place-items: center; | ||
|
||
@media (max-width: 600px) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from "vite"; | ||
|
||
export default defineConfig(({ command, mode, ssrBuild }) => { | ||
return { | ||
server: { | ||
open: true, | ||
}, | ||
}; | ||
}); |