@triptease/tt-navbar
v0.0.77
Published
Webcomponent tt-navbar following open-wc recommendations
Readme
<tt-navbar>
This webcomponent follows the open-wc recommendation.
Installation
npm i tt-navbarUsage
<script type="module">
import 'tt-navbar/tt-navbar.js';
</script>
<tt-navbar client-key="your-client-key" platform-url="https://localhost.triptease.io:3500"></tt-navbar>Properties
| Property | Type | Description |
| ---------------------- | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| client-key | string | The client key identifier |
| platform-url | string | Base URL for the platform |
| campaign-manager-url | string | Campaign manager URL |
| active-route | string | The currently active route |
| clients | Array<{clientKey: string, displayName: string}> | Array of client objects for multi-client selector |
| navigate | Function | Custom navigation handler function |
| onClientChange | Function | Callback function that receives the selected client key as a string when the client selection changes |
Multi-Client Selector
When multiple clients are provided, the navbar will display a combobox selector:
const navbar = document.querySelector('tt-navbar');
// Pass clients as a property
navbar.clients = [
{ clientKey: 'client1', displayName: 'Client One' },
{ clientKey: 'client2', displayName: 'Client Two' },
];
// Handle client change - typically you would redirect the user to the new client
navbar.onClientChange = (selectedClientKey) => {
// Update the URL to reflect the new client
window.location.href = `/home/${selectedClientKey}`;
// Or use your router's navigation method
// router.navigate(`/home/${selectedClientKey}`);
};Note: When a user changes the selected client, you typically want to redirect them to the same page/route but for the new client context.
Alternatively, you can pass clients as a JSON string attribute:
<tt-navbar
client-key="client1"
clients='[{"clientKey":"client1","displayName":"Client One"},{"clientKey":"client2","displayName":"Client Two"}]'
></tt-navbar>Linting and formatting
To scan the project for linting and formatting errors, run
npm run lintTo automatically fix linting and formatting errors, run
npm run formatTesting with Web Test Runner
To execute a single test run:
npm run testTo run the tests in interactive watch mode run:
npm run test:watchDemoing with Storybook
To run a local instance of Storybook for your component, run
npm run storybookTo build a production version of Storybook, run
npm run storybook:buildTooling configs
For most of the tools, the configuration is in the package.json to reduce the amount of files in your project.
If you customize the configuration a lot, you can consider moving them to individual files.
Local Demo with web-dev-server
npm startTo run a local development server that serves the basic demo located in demo/index.html
