Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example/static components #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/basic/static-components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
9 changes: 9 additions & 0 deletions examples/basic/static-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Static Components

A demo showing a simple site built with (non stateful) components using SolidJS

Features:

- CSS modules
- Solid components (non stateful)
- Global styling and custom props in `src/index.css`
20 changes: 20 additions & 0 deletions examples/basic/static-components/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel="shortcut icon" type="image/ico" href="/src/assets/favicon.ico" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"
/>
<title>Solid App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<script src="/src/index.tsx" type="module"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions examples/basic/static-components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "vite-template-solid",
"version": "0.0.0",
"description": "",
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"license": "MIT",
"devDependencies": {
"typescript": "^4.6.4",
"vite": "^2.9.9",
"vite-plugin-solid": "^2.2.6"
},
"dependencies": {
"solid-js": "^1.4.2"
}
}
3 changes: 3 additions & 0 deletions examples/basic/static-components/src/App.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.App {
text-align: center;
}
20 changes: 20 additions & 0 deletions examples/basic/static-components/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Component } from 'solid-js';

import styles from './App.module.css';
import { CardGrid } from './components/CardGrid';
import { Navbar } from './components/Navbar';
import { Title } from './components/Title';

const App: Component = () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that one common style should be used for Components, I think that export default function FunctionName is also used in the tutorial on site. So export default function App here?

return (
<div class={styles.App}>
<Navbar />
<main>
<Title />
<CardGrid />
</main>
</div>
);
};

export default App;
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.grid {
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
margin-top: 3rem;
}

.card {
margin: 1rem;
flex-basis: 45%;
padding: 1.5rem;
text-align: left;
color: inherit;
text-decoration: none;
border: 1px solid #eaeaea;
border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease;
}

.card:hover,
.card:focus,
.card:active {
color: var(--sLight-blue);
border-color: var(--sLight-blue);
}

.card h3 {
margin: 0 0 1rem 0;
font-size: 1.5rem;
}

.card p {
margin: 0;
font-size: 1.25rem;
line-height: 1.5;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import styles from './CardGrid.module.css';
export default function CardGrid() {
return (
<div class={styles.grid}>
<a href="https://www.solidjs.com/" target="_new" class={styles.card}>
<h3>Documentation &rarr;</h3>
<p>Find comprehensive information about Solid features and API.</p>
</a>

<a
href="https://www.solidjs.com/tutorial/introduction_basics"
target="_new"
class={styles.card}
>
<h3>Learn &rarr;</h3>
<p>Learn Solid through our interactive tutorial!</p>
</a>

<a href="https://www.solidjs.com/examples/counter" target="_new" class={styles.card}>
<h3>Examples &rarr;</h3>
<p>Checkout our gallery of Solid example projects.</p>
</a>

<a href="https://www.solidjs.com/examples/counter" target="_new" class={styles.card}>
<h3>Play &rarr;</h3>
<p>Visit the playground to test ideas and see Solid compiled output!</p>
</a>

<a href="https://netlify.com" target="_new" class={styles.card}>
<h3>Deploy &rarr;</h3>
<p>Instantly deploy your Solid app to a public URL with Netlify.</p>
</a>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as CardGrid } from './CardGrid';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.nav {
background-color: var(--sLight-blue);
padding: 1.5rem 3rem;
}

.nav > div {
max-width: 800px;
margin: 0 auto;
display: flex;
justify-content: space-between;
}

.logo {
width: 2.25rem;
pointer-events: none;
}
14 changes: 14 additions & 0 deletions examples/basic/static-components/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import styles from './Navbar.module.css';
import logo from '../../logo.svg';
import { SocialList } from '../SocialList';

export default function () {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a name to the function here, for consistency sake?

return (
<div class={styles.nav}>
<div>
<img src={logo} alt="logo" class={styles.logo} />
<SocialList />
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Navbar } from './Navbar';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.socialList {
margin: 0;
padding: 0;
display: flex;
}

.socialList > li {
margin-left: 0.5rem;
}

.socialList i {
font-size: 2rem;
color: white;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import styles from './SocialList.module.css';
export default function SocialList() {
return (
<ul role="list" class={styles.socialList}>
<li>
<a href="https://github.com/solidjs/solid">
<span class="sr-only">Navigate to Github</span>
<i class="fa-brands fa-github-square"></i>
</a>
</li>
<li>
<a href="https://www.reddit.com/r/solidjs/">
<span class="sr-only">Navigate to Reddit</span>
<i class="fa-brands fa-reddit-square"></i>
</a>
</li>
<li>
<a href="https://discord.com/invite/solidjs">
<span class="sr-only">Navigate to Discord</span>
<i class="fa-brands fa-discord"></i>
</a>
</li>
<li>
<a href="https://twitter.com/solid_js">
<span class="sr-only">Navigate to Twitter</span>
<i class="fa-brands fa-twitter-square"></i>
</a>
</li>
</ul>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as SocialList } from './SocialList';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.title {
margin: 0 auto;
line-height: 1.15;
font-size: 4rem;
margin-top: 3rem;
max-width: 700px;
}

.title span {
color: var(--sLight-blue);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import styles from './Title.module.css';
export default function Title() {
return (
<h1 class={styles.title}>
Simple and performant, <span>SolidJS!</span>
</h1>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Title } from './Title';
109 changes: 109 additions & 0 deletions examples/basic/static-components/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
{{
Copy link

@milomg milomg Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSS RESET
*/

/* Box sizing rules */
*,
*::before,
*::after {
box-sizing: border-box;
}

/* Remove default margin */
body,
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd {
margin: 0;
}

/* Remove list styles on ul, ol elements with a list role, which suggests default styling will be removed */
ul[role='list'],
ol[role='list'] {
list-style: none;
}

/* Set core root defaults */
html:focus-within {
scroll-behavior: smooth;
}

/* Set core body defaults */
body {
min-height: 100vh;
text-rendering: optimizeSpeed;
line-height: 1.5;
}

/* A elements that don't have a class get default styles */
a:not([class]) {
text-decoration-skip-ink: auto;
}

/* Make images easier to work with */
img,
picture {
max-width: 100%;
display: block;
}

/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
font: inherit;
}

/* Remove all animations, transitions and smooth scroll for people that prefer not to see them */
@media (prefers-reduced-motion: reduce) {
html:focus-within {
scroll-behavior: auto;
}

*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
/*
end CSS reset
}}
*/

:root {
--sLight-blue: #446b9e;
}
body {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell,
Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
}

.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
7 changes: 7 additions & 0 deletions examples/basic/static-components/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* @refresh reload */
import { render } from 'solid-js/web';

import './index.css';
import App from './App';

render(() => <App />, document.getElementById('root') as HTMLElement);
1 change: 1 addition & 0 deletions examples/basic/static-components/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading