Skip to content

Commit

Permalink
feat: add fast-components package (#2677)
Browse files Browse the repository at this point in the history
* adding base files

* set up example component

* adding description of storybook error

* add test script

* cleanup

* fixing build script and adjusting readme

* removing unnecessary try/catch

* add tree-shaking comment

* adds code owners

* clarify language in readme

* categorize dependencies correctly
  • Loading branch information
nicholasrice authored Feb 14, 2020
1 parent 99a24d8 commit 9f37cbb
Show file tree
Hide file tree
Showing 19 changed files with 3,761 additions and 62 deletions.
5 changes: 4 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ build/ @janechu @nicholasrice @chrisdholt @awentzel
/packages/fast-figma-plugin-msft/ @nicholasrice @bheston @e-vanaubrey @Jeremy-Knudsen

# fast-element
/packages/fast-element/ @EisenbergEffect @chrisdholt @janechu @nicholasrice
/packages/fast-element/ @EisenbergEffect @chrisdholt @janechu @nicholasrice

# fast-components
/packages/fast-components/ @EisenbergEffect @chrisdholt @janechu @nicholasrice
7 changes: 7 additions & 0 deletions packages/fast-components/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Tests
__test__/
*.spec.*
*.test.*

# Source files
src/
1 change: 1 addition & 0 deletions packages/fast-components/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 2 additions & 0 deletions packages/fast-components/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage/*
dist/*
16 changes: 16 additions & 0 deletions packages/fast-components/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
stories: ["../src/**/*.stories.ts"],
webpackFinal: async config => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve("awesome-typescript-loader"),
},
],
});
config.resolve.extensions.push(".ts");

return config;
},
};
12 changes: 12 additions & 0 deletions packages/fast-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# FAST Components

## Development

To start the component development environment, run `yarn start`.

### Known issue with Storybook site hot-reloading

Storybook will watch modules for changes and hot-reload the module when necessary. This is usually great but poses a problem when the module being hot-reloaded defines a custom element. A custom element name can only be defined by the `CustomElementsRegistry` once, so reloading a module that defines a custom element will attempt to re-register the custom element name, throwing an error because the name has already been defined. This error will manifest with the following message:
`Failed to execute 'define' on 'CustomElementRegistry': the name "my-custom-element-name" has already been used with this registry`

This is a known issue and will indicate that you need to refresh the page. We're working on surfacing a more instructive error message for this case.
44 changes: 44 additions & 0 deletions packages/fast-components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@microsoft/fast-components",
"description": "A library of Web Components",
"private": true,
"sideEffects": false,
"version": "0.0.0",
"author": {
"name": "Microsoft",
"url": "https://discord.gg/FcSNfg4"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/Microsoft/fast-dna.git"
},
"bugs": {
"url": "https://github.com/Microsoft/fast-dna/issues/new/choose"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc -p ./tsconfig.build.json",
"clean:dist": "node ../../build/clean.js dist",
"prepare": "yarn clean:dist && yarn build",
"prettier": "prettier --config ../../.prettierrc --write \"**/*.ts\"",
"prettier:diff": "prettier --config ../../.prettierrc \"**/*.ts\" --list-different",
"tslint": "tslint -c ./tslint.json '**/*.ts'",
"tslint:fix": "tslint -c ./tslint.json --fix '**/*.ts'",
"start": "start-storybook -p 6006",
"test": "yarn build-storybook && yarn tslint",
"build-storybook": "build-storybook"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@storybook/cli": "^5.3.13",
"@storybook/html": "^5.3.13",
"awesome-typescript-loader": "^5.2.1",
"prettier": "1.14.3",
"typescript": "^3.7.5"
},
"dependencies": {
"@microsoft/fast-element": "^0.0.0"
}
}
1 change: 1 addition & 0 deletions packages/fast-components/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./name-tag";
2 changes: 2 additions & 0 deletions packages/fast-components/src/name-tag/fixtures/mark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<fast-name-tag>Mark!</fast-name-tag>
<fast-name-tag style="--background-color: #00F">Blue Mark!</fast-name-tag>
14 changes: 14 additions & 0 deletions packages/fast-components/src/name-tag/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { customElement } from "@microsoft/fast-element";
import { NameTag } from "./name-tag";
import { NameTagTemplate } from "./name-tag.template";
import { NameTagStyles } from "./name-tag.styles";

@customElement({
name: "fast-name-tag",
template: NameTagTemplate,
dependencies: [NameTagStyles],
})
export class FASTNameTag extends NameTag {}
export * from "./name-tag.template";
export * from "./name-tag.styles";
export * from "./name-tag";
11 changes: 11 additions & 0 deletions packages/fast-components/src/name-tag/name-tag.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FASTNameTag } from ".";
import MarkTemplate from "./fixtures/mark.html";

// Prevent tree-shaking
FASTNameTag;

export default {
title: "Name tag",
};

export const Mark = () => MarkTemplate;
63 changes: 63 additions & 0 deletions packages/fast-components/src/name-tag/name-tag.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { css } from "@microsoft/fast-element";

export const NameTagStyles = css`
:host {
--depth: 4;
--background-color: #f00;
--border-radius: 4;
display: block;
color: white;
background: var(--background-color);
border-radius: var(--border-radius);
min-width: 325px;
max-width: 500px;
text-align: center;
box-shadow: 0 0 calc(var(--depth) * 1px) rgba(0, 0, 0, 0.5);
}
.header {
margin: 16px 0;
position: relative;
}
h3 {
font-weight: bold;
font-family: "Source Sans Pro";
letter-spacing: 4px;
font-size: 32px;
margin: 0;
padding: 0;
}
h4 {
font-family: sans-serif;
font-size: 18px;
margin: 0;
padding: 0;
}
.body {
background: white;
color: black;
padding: 32px 8px;
font-size: 42px;
font-family: cursive;
}
.footer {
height: 16px;
background: var(--background-color);
border-radius: 0 0 var(--border-radius) var(--border-radius);
}
::slotted(img) {
border-radius: 50%;
height: 64px;
width: 64px;
box-shadow: 0 0 calc(var(--depth) / 2px) rgba(0, 0, 0, 0.5);
position: absolute;
left: 16px;
top: -4px;
}
`;
16 changes: 16 additions & 0 deletions packages/fast-components/src/name-tag/name-tag.template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { html } from "@microsoft/fast-element";
import { NameTag } from "./name-tag";

export const NameTagTemplate = html<NameTag>`
<div class="header">
<slot name="avatar"></slot>
<h3>${x => x.greeting.toUpperCase()}</h3>
<h4>my name is</h4>
</div>
<div class="body">
<slot></slot>
</div>
<div class="footer"></div>
`;
6 changes: 6 additions & 0 deletions packages/fast-components/src/name-tag/name-tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { attr, FastElement } from "@microsoft/fast-element";

export class NameTag extends FastElement {
@attr
public greeting: string = "Hello";
}
4 changes: 4 additions & 0 deletions packages/fast-components/src/storybook-typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.html" {
const value: string;
export default value;
}
7 changes: 7 additions & 0 deletions packages/fast-components/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"exclude": [
"**/*.stories.ts",
"./src/storybook-typings.d.ts"
]
}
17 changes: 17 additions & 0 deletions packages/fast-components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"baseUrl": ".",
"strictNullChecks": true,
"experimentalDecorators": true,
"skipLibCheck": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
22 changes: 22 additions & 0 deletions packages/fast-components/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": [
"@microsoft/fast-tslint-rules",
"tslint-config-prettier"
],
"rules": {
"typedef": [
true,
"call-signature",
"parameter",
"property-declaration",
"member-variable-declarations"
]
},
"linterOptions": {
"exclude": [
"node_modules/**",
"dist/**",
"src/**/*.stories.ts"
]
}
}
Loading

0 comments on commit 9f37cbb

Please sign in to comment.