Skip to content

Commit

Permalink
Merge pull request #31 from kacper-cyra/ui-18/add_portrait_component
Browse files Browse the repository at this point in the history
add portrait component
  • Loading branch information
kacper-cyra authored Dec 12, 2021
2 parents 3aa4b57 + 327872f commit 736742f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README_NEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Conventions

For file structure reference this [repo](https://github.com/wiledal/vanilla-bean).

Branches are named after category, task number and with meaningful description. E.g.'ui-18/add_portrait_component'.

## Warnings

Parcel in v2 has a [bug](https://github.com/parcel-bundler/parcel/issues/5965) witch it's cache and will not update changes on website without manual page refresh.

## Useful resources

- [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements),
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<body>
<div id="swquiz-app"></div>

<script src="src/index.js" type="module"></script>
<script src="./src/index.js" type="module"></script>
</body>
</html>
4 changes: 3 additions & 1 deletion src/app/App.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const App = ({ options }) => {};
export const App = ({ options: { rootNodeId } }) => {
const rootNode = document.getElementById(rootNodeId);
};
30 changes: 30 additions & 0 deletions src/components/Portrait/Portrait.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as classes from './style.module.scss';

export const PORTRAIT_COMPONENT_NAME = 'portrait-component';

class Portrait extends HTMLElement {
constructor() {
super();
this._contents = new DocumentFragment();

this.imageContainer = Portrait.imageContainerBuilder();

this._contents.appendChild(this.imageContainer);
}

connectedCallback() {
this.imageContainer.style.backgroundImage = `url(${this.getAttribute(
'data-image-url',
)})`;
this.appendChild(this._contents);
}

static imageContainerBuilder() {
const imageContainer = document.createElement('div');
imageContainer.className = classes.imageContainer;

return imageContainer;
}
}

customElements.define(PORTRAIT_COMPONENT_NAME, Portrait);
11 changes: 11 additions & 0 deletions src/components/Portrait/style.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@use '../../themes/theme.scss' as *;

.portrait {
display: flex;
flex: 1;
box-shadow: $red-box-shadow;
border-radius: $border-radius;
min-height: 100px;
background-size: cover;
background-position: center;
}
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ const SW_API_BASE_URL = process.env.SW_API_BASE_URL || 'https://swapi.dev/api';
const QUIZ_MAX_TIME = process.env.QUIZ_MAX_TIME_SECONDS
? process.env.QUIZ_MAX_TIME_SECONDS * ONE_SECOND_MILLIS
: 120 * ONE_SECOND_MILLIS;
const ROOT_NODE_ID = 'swquiz-app';

window.onload = () =>
window.onload = () => {
App({
options: {
swApiBaseUrl: SW_API_BASE_URL,
quizMaxTime: QUIZ_MAX_TIME,
rootNodeId: ROOT_NODE_ID,
},
});
};
3 changes: 3 additions & 0 deletions src/themes/theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$red-box-shadow: 4px 4px 40px 0px #ff0000e5, 0px 4px 4px 0px #00000040;

$border-radius: 16px;

0 comments on commit 736742f

Please sign in to comment.