Skip to content

Commit

Permalink
feat(app-bar): add AppBar component
Browse files Browse the repository at this point in the history
  • Loading branch information
si3nloong committed May 28, 2021
1 parent 9c47ae9 commit d0a1642
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 17 deletions.
40 changes: 40 additions & 0 deletions components/app-bar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @responsive-ui/app-bar

> An app bar component of responsive-ui.
<p>

[![Svelte v3](https://img.shields.io/badge/svelte-v3-orange.svg)](https://svelte.dev)
[![npm](https://img.shields.io/npm/v/@responsive-ui/app-bar.svg)](https://www.npmjs.com/package/@responsive-ui/app-bar)
[![Bundle Size](https://badgen.net/bundlephobia/minzip/%40responsive-ui%2Fapp-bar)](https://bundlephobia.com/result?p=@responsive-ui/app-bar)
[![download](https://img.shields.io/npm/dw/@responsive-ui/app-bar.svg)](https://www.npmjs.com/package/@responsive-ui/app-bar)
[![LICENCE](https://img.shields.io/github/license/wetix/responsive-ui)](https://github.com/wetix/responsive-ui/blob/master/LICENSE)

</p>

## Install

```console
npm install @responsive-ui/app-bar
```

or

```console
yarn add @responsive-ui/app-bar
```

## Sponsors

<img src="https://asset.wetix.my/images/logo/wetix.png" alt="WeTix" width="240px">

## License

[@responsive-ui/app-bar](https://github.com/wetix/responsive-ui/tree/master/components/app-bar) is 100% free and open-source, under the [MIT license](https://github.com/wetix/responsive-ui/blob/master/LICENSE).

## Big Thanks To

Thanks to these awesome companies for their support of Open Source developers ❤

[![GitHub](https://jstools.dev/img/badges/github.svg)](https://github.com/open-source)
[![NPM](https://jstools.dev/img/badges/npm.svg)](https://www.npmjs.com/)
49 changes: 49 additions & 0 deletions components/app-bar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@responsive-ui/app-bar",
"version": "1.0.1-alpha.0",
"description": "An app bar component of responsive-ui.",
"author": "Si3nLoong <sianloong90@gmail.com> (https://github.com/si3nloong)",
"homepage": "https://github.com/wetix/responsive-ui/blob/master/components/app-bar#README.md",
"license": "MIT",
"main": "lib/index.cjs",
"browser": "lib/index.js",
"module": "lib/index.mjs",
"unpkg": "lib/index.min.js",
"svelte": "src/AppBar.svelte",
"types": "types/index.d.ts",
"publishConfig": {
"access": "public"
},
"keywords": [
"svelte",
"ui-component",
"responsive-ui",
"app-bar",
"svelte-app-bar"
],
"peerDependencies": {
"svelte": "^3.27.0",
"svelte-preprocess": "^4.5.0",
"typescript": "^4.0.0"
},
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib",
"types",
"src"
],
"repository": {
"type": "git",
"url": "git+https://github.com/wetix/responsive-ui.git"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/wetix/responsive-ui/issues"
},
"gitHead": "fd5010a4fe0e250d52c7292f70d8e3702b7ffcfe"
}
101 changes: 101 additions & 0 deletions components/app-bar/src/AppBar.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<script lang="ts">
let className = "";
export { className as class };
export let title = "";
export let hasBg = false;
export let style = "";
let height = 200;
let y = height;
let clientHeight: number = 0;
let innerWidth: number = 0;
const handleScroll = () => {
let offsetY = height - window.scrollY * 0.5;
if (offsetY <= 0) offsetY = 0;
y = offsetY;
};
</script>

<svelte:window on:scroll={handleScroll} bind:innerWidth />

<header
class="responsive-ui-app-bar {className}"
class:responsive-ui-app-bar--float={y === 0}
class:responsive-ui-app-bar--with-bg={hasBg}
bind:clientHeight
>
<div class="responsive-ui-app-bar__header">
<slot name="left">{title}</slot>
<slot name="right" />
</div>
<slot />
</header>
{#if hasBg}
<div class="responsive-ui-app-bar__semi-circ" {style}>
<svg {height} width="100%">
<ellipse
cx={innerWidth / 2}
cy="0"
rx={innerWidth * 0.65}
ry={y}
style="fill:#fc4451;"
/>
</svg>
</div>
{/if}

<style lang="scss">
.responsive-ui-app-bar {
position: fixed;
box-sizing: border-box;
padding: var(--padding);
background: #fff;
top: 0;
left: 0;
width: 100%;
z-index: 50;
&--with-bg {
background: #fc4451;
color: #fff;
}
&--float {
color: #000;
background: #fff;
box-shadow: 0px 1px 10px rgba(0, 0, 0, 0.1);
}
&__header {
display: flex;
justify-content: space-between;
align-items: center;
transition: all 0.5s;
text-transform: capitalize;
font-size: var(--font-size-lg);
font-weight: 600;
}
&__semi-circ {
position: fixed;
left: 0;
top: 0;
width: 100%;
z-index: -1;
height: 210px;
@media screen and (min-width: 640px) {
display: none;
}
}
@media screen and (min-width: 640px) {
color: #000;
background: #fff;
box-shadow: 0px 1px 10px rgba(0, 0, 0, 0.1);
}
}
</style>
23 changes: 23 additions & 0 deletions components/app-bar/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { SvelteComponentTyped } from "svelte/internal";

export interface AppBarProps {
class?: string;
title?: string;
hasBg?: boolean;
style?: string;
}

export interface AppBarEvents {}

export interface AppBarSlots {
left: {};
right: {};
}

declare class AppBar extends SvelteComponentTyped<
AppBarProps,
AppBarEvents,
AppBarSlots
> {}

export default AppBar;
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"node": ">=14.0.0"
},
"devDependencies": {
"@babel/core": "^7.14.0",
"@babel/core": "^7.14.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.14.1",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"@babel/runtime": "^7.14.0",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-babel": "^5.3.0",
Expand All @@ -39,40 +39,40 @@
"@storybook/addon-links": "^6.2.9",
"@storybook/addon-viewport": "^6.2.9",
"@storybook/svelte": "^6.2.9",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/svelte": "^3.0.3",
"@tsconfig/svelte": "^1.0.10",
"@types/jest": "^26.0.20",
"babel-jest": "^26.6.3",
"@tsconfig/svelte": "^1.0.12",
"@types/jest": "^26.0.23",
"babel-jest": "^27.0.1",
"babel-loader": "^8.2.2",
"camelcase": "^6.2.0",
"chalk": "^4.1.1",
"css-loader": "^5.2.4",
"css-loader": "^5.2.6",
"faker": "^5.5.3",
"file-loader": "^6.2.0",
"fs-extra": "^10.0.0",
"jest": "^26.6.3",
"jest": "^27.0.1",
"jest-transform-svelte": "^2.1.1",
"lerna": "^4.0.0",
"rollup": "^2.45.2",
"rollup": "^2.50.2",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^7.1.0",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.32.12",
"sass-loader": "^11.0.1",
"sirv-cli": "^1.0.11",
"sass": "^1.34.0",
"sass-loader": "^11.1.1",
"sirv-cli": "^1.0.12",
"style-loader": "^2.0.0",
"svelte": "^3.38.2",
"svelte-check": "^1.5.2",
"svelte-jester": "^1.5.0",
"svelte-check": "^1.6.0",
"svelte-jester": "^1.6.0",
"svelte-jsx": "^2.0.0",
"svelte-loader": "^3.1.1",
"svelte-preprocess": "^4.7.3",
"tslib": "^2.2.0",
"typescript": "^4.2.4",
"typescript": "^4.3.2",
"url-loader": "^4.1.1",
"vite": "^2.2.4"
"vite": "^2.3.4"
},
"jest": {
"transform": {
Expand Down
11 changes: 11 additions & 0 deletions packages/svelte-responsive-ui-preprocess/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `svelte-responsive-ui-preprocess`

> TODO: description
## Usage

```
const svelteResponsiveUiPreprocess = require('svelte-responsive-ui-preprocess');
// TODO: DEMONSTRATE API
```
26 changes: 26 additions & 0 deletions packages/svelte-responsive-ui-preprocess/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "svelte-responsive-ui-preprocess",
"version": "1.0.1-alpha.0",
"description": "> TODO: description",
"author": "Si3nLoong <sianloong90@gmail.com>",
"homepage": "https://github.com/wetix/responsive-ui#readme",
"license": "ISC",
"main": "lib/svelte-responsive-ui-preprocess.js",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib"
],
"repository": {
"type": "git",
"url": "git+https://github.com/wetix/responsive-ui.git"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/wetix/responsive-ui/issues"
}
}
3 changes: 3 additions & 0 deletions packages/svelte-responsive-ui-preprocess/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const preproccess = () => {};

export default preproccess;
4 changes: 4 additions & 0 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import AppBar from "../components/app-bar/src/AppBar.svelte";
import Accordion from "../components/accordion/src/Accordion.svelte";
import BottomBar from "../components/bottom-bar/src/BottomBar.svelte";
import BottomSheet from "../components/bottom-sheet/src/BottomSheet.svelte";
Expand Down Expand Up @@ -432,8 +433,10 @@
let openRightDock = false;
let placement = "left";
</script>

<AppBar title="XXXX" />
<main>
<Badge count={1}>testing</Badge>
<Badge count={0}>testing</Badge>
Expand Down Expand Up @@ -893,4 +896,5 @@
:global(span[label], span[data-tooltip]) {
background: #f5f5f5;
}
</style>

0 comments on commit d0a1642

Please sign in to comment.