Reusable Tradeshift UI Components as Web Components https://tradeshift.github.io/elements
- Install the core package of the Elements
$ npm i @tradeshift/elements --save
- Install the package of the component you need (available components)
$ npm i @tradeshift/elements.button --save
- Import the component
import '@tradeshift/elements.button';
or
<script src="node_modules/@tradeshift/elements/lib/core.umd.js"></script>
<script src="node_modules/@tradeshift/elements.button/lib/button.umd.js"></script>
- Import the css variables
import '@tradeshift/elements/src/vars.css';
or
<link rel="stylesheet" href="node_modules/@tradeshift/elements/src/vars.css" />
- Use it
<ts-button type="primary"> Sample Button </ts-button>
- Our components rely on having the
Open Sans
available, You can see thefont-weight
andfont-style
you need to load here, or you can just load it from our package (for now)
<link rel="stylesheet" href="node_modules/@tradeshift/elements/src/fonts.css" />
For supporting IE11 you need to do couple of more things
-
If you are using the Tradeshift-ui you need to upgrade it to a compatible version:
- For version
12
you should upgrade to12.2.9
or newer version - For version
11
you should upgrade to11.3.2
or newer version
- For version
-
Don't shim CSS Custom Properties in IE11
<!-- Place this in the <head>, before the Web Component polyfills are loaded -->
<script>
if (!window.Promise) {
window.ShadyCSS = { nativeCss: true };
}
</script>
- Installation
$ npm i @open-wc/polyfills-loader
- Load it
import loadPolyfills from '@open-wc/polyfills-loader';
loadPolyfills().then(() => import('./my-app.js'));
- Installation
$ npm i @webcomponents/webcomponentsjs --save
- Enable ES5 class-less Custom Elements
<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
- Load appropriate polyfills and shims with
@webcomponents/webcomponentsjs
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js" defer></script>
- Load the core and components scripts after
WebComponensReady
event:
<!-- Load Tradeshift Elements once the polyfills are ready -->
<script>
window.addEventListener('WebComponentsReady', function () {
// Load Tradeshift Elements core package
var coreEl = document.createElement('script');
coreEl.setAttribute('src', '/packages/core/lib/core.umd.js');
document.body.appendChild(coreEl);
// Load other Tradeshift Elements once the core package is loaded
coreEl.onload = function () {
var components = ['root', 'button'];
components.forEach(function (component) {
var el = document.createElement('script');
el.setAttribute('src', '/packages/components/' + component + '/lib/' + component + '.umd.js');
document.body.appendChild(el);
});
};
});
</script>
- Make sure your node version is > 10. If you are using
nvm
you can just run:
$ nvm use
- We are using lerna to manage our components in single repo but their own packages, so for installation you need to run:
$ npx lerna bootstrap # bootstrap all packages and make sure they work together
- You can start the development server which is watching for changes:
$ npm start
- Open http://127.0.0.1:8080/, or e.g. http://127.0.0.1:8080/packages/components/{PACKAGE_NAME}/ if you want to test a specific element and that element (PACKAGE_NAME) has got an
index.html
file. If not, feel free to add one. Example: http://127.0.0.1:8080/packages/components/action-select/
Thanks for your interest and help!
- First thing you need to do is read this [Component Checklist] which contains lots of important information about what you need to consider when you are creating/changing components
You can find some links to useful materials about what we are using and some tutorials and articles that can help you get started.
- Extend
TSElement
, instead ofLitElement
- Import
css
,unsafeCSS
&html
from@tradeshift/elements
instead oflit-html
- Add the UMD global namespace to
rollup.globals.json
- Add your package to the
package.json
dependencies
To make it simpler and more consistent, we added a Component generator
, You can use our its script to generate a new component from terminal and it will create the component inside packages/components
- NOTE: Still you need to add the UMD global namespace to
rollup.globals.json
and add your package to thepackage.json
dependencies, for now
$ npm run component-gen
We are using lerna to publish our elements
- Checkout a master branch.
- Run the
npm run new-version
command. It will invoke a shell script that:- calculate a new version number
- create a new branch with new version number and a new git tag
- generate CHANGELOG.md for all components
- make a commit with a predefined commit message to created branch
- push this branch and git tag to origin
- Go to Github and create a PR from the branch created at previous step.
- After merge a new version of elements will be built and published to NPM registry and Github Packages.
You can see a list of limitations that we should watch out for, here
- You can always create forks on GitHub, submit Issues and Pull Requests.
- You can only use Tradeshift Elements to make apps on a Tradeshift platform, e.g. tradeshift.com.
- You can fix a bug until the bugfix is deployed by Tradeshift.
- You can host Tradeshift Elements yourself.
- If you want to make a bigger change or just want to talk with us, reach out to our team here on GitHub.
You can read the full license agreement in the LICENSE.md.