I am rewriting a complex Visualforce component into LWC. It's an activity timeline / Gantt chart that's part of a managed package.
The old version let the end users override the bar colo(u)rs with a hierarchy custom setting. Org / Profile / User level was perfect for the job.
In the VF component I simply had a bunch of these
<style>
.fn-gantt .Reservation-Account {
background-color: {!BLANKVALUE($Setup.Calendar__c.Reservation_Account_background_color__c, '#36C')};
}
.fn-gantt .Reservation-Contact {
background-color: {!BLANKVALUE($Setup.Calendar__c.Reservation_Contact_background_color__c, '#B82E2E')};
}
</style>
I am wondering what is the best way to give similar power over the LWC version of the component to the end users' admins.
- There's no nice access to custom settings, fine, I can fetch it with Apex
- but I can't put
<style>
tags in the LWC's component (html) file - chart bars will be rendered with some iteration or even using
lwc:dom="manual"
so a dynamic getter trick won't work - CSS file can't have variables. No references to custom setting or custom labels
- clients of managed packages can't reuse the installed components in their own. So normal parent-child mechanisms like
@api
, using slots to pass markup or even using a Static Resource with CSS overrides won't work. - Same with styling hooks I think. I won't be using standard components like
lightning-pill
for bars so the styling hooks don't help? I know hooks for custom components are coming in Summer'21 but still - if end user can't reuse my component in their own, how would they apply the overrides. - I can
loadStyle
my own static resource but I think it's checked at compile time, no way to load it dynamic. And if there's some hack - might break in future
So far I can think of three things, they all feel bit "meh".
- Wrap it in Aura with
access="global"
, end user should be then able to reuse the Aura component. - Create
Style__c
Text(255) on every sObject used as bar. NotClass__c
because how would they pass me the class definitions. - Publish the source code (IP problems, competition advantages, upgrade problems, yadda yadda... and what about orgs on Group Edition that have no custom coding capabilities)
Any clever ideas?