craftos-ui v0.1.77
CraftOS UI contains the React Components we share between the different Craft Projects.
Installation
CraftOS UI is available as a private npm package.
Before you can install you need to finish the authentication in the Usage step.
npm:
npm install @craftos/ui
yarn:
yarn add @craftos/ui
Usage
To use CraftOS UI you need to authenticate yourself. This is because we are using Azure DevOps private feed.
Here is the guide to authenticate using a .npmrc file. https://learn.microsoft.com/en-us/azure/devops/artifacts/npm/npmrc#tabpanel_1_linux
- Copy snippit into your personal
.npmrc
file. If you don't have one just create it in your user folder. - Generate a new token in Azure DevOps
- Convert token to Base64
- Replace placeholder
[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
with your token.
; begin auth token
//pkgs.dev.azure.com/enpal/craftOS/_packaging/craftOS-UI/npm/registry/:username=[ANY_VALUE_BUT_NOT_AN_EMPTY_STRING]
//pkgs.dev.azure.com/enpal/craftOS/_packaging/craftOS-UI/npm/registry/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//pkgs.dev.azure.com/enpal/craftOS/_packaging/craftOS-UI/npm/registry/:email=[NPM REQUIRES AN EMAIL]
//pkgs.dev.azure.com/enpal/craftOS/_packaging/craftOS-UI/npm/:username=[ANY_VALUE_BUT_NOT_AN_EMPTY_STRING]
//pkgs.dev.azure.com/enpal/craftOS/_packaging/craftOS-UI/npm/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//pkgs.dev.azure.com/enpal/craftOS/_packaging/craftOS-UI/npm/:email=[NPM REQUIRES AN EMAIL]
; end auth token
- Add this snippit to the project
.npmrc
file
registry=https://pkgs.dev.azure.com/enpal/craftOS/_packaging/craftOS-UI/npm/registry/
always-auth=true
- You should now be able to install CraftOS UI.
Authenticate in the pipeline
All you need to do is add this in your pipeline:
- task: npmAuthenticate@0
displayName: 'Auhenticate NPM'
inputs:
workingFile: .npmrc
Publish new version
- Build project:
yarn build
Bump the version in package.json
Publish to npm:
npm publish
Components
AppLayout
Component that wraps the whole page, this includes the NavBar. Use this as your page wrapper.
Example
<AppLayout>
<PageContent />
</AppLayout>
API
Property | Description | Type | Default |
---|---|---|---|
children | The content to be shown inside the layout. | ReactNode | - |
appName? | Name of app shown beside logo | string | CraftOS |
onLanguageChange? | Function that changes the language of the site | (value: string) => void | - |
currentLanguage | Language that is currently set in the application | "en-US" | "de-DE" | - |
user | User object | User: {name: string, email: string, roles: Roles[] | []} | - |
t | Translation function | (arg0: string) => string | - |
onLogout | Logout function | () => void | - |
appEnviroment | Enviroment string to render app links | "development" | "test" | "staging" | "production" | - |
Header
The navbar component used in all CraftOS applications.
Example
<Header />
API
Property | Description | Type | Default |
---|---|---|---|
appName? | Name of app shown beside logo | string | CraftOS |
onLanguageChange? | Function that changes the language of the site | (value: string) => void | - |
currentLanguage | Language that is currently set in the application | "en-US" | "de-DE" | - |
user | User object | User: {name: string, email: string, roles: Roles[] | []} | - |
t | Translation function | (arg0: string) => string | - |
onLogout | Logout function | () => void | - |
appEnviroment | Enviroment string to render app links | "development" | "test" | "staging" | "production" | - |
BoxWrapper
Wrapper component for box elements. Adds for example padding and shadow around your items.
Example
<BoxWrapper>
<h1>This is a box</h1>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</BoxWrapper>
API
Property | Description | Type | Default |
---|---|---|---|
children | The content to be shown inside the layout. | ReactNode | - |
fullHeight | Adds height 100% to the wrapper | boolean | false |