Open Exlord opened 4 years ago
Class names are prefixed as a unique identifier and can change in both development and production mode. That means you can't use css files (be it css, scss, ...) to customize Alyle UI components.
There are other ways to customize Alyle UI components. You can add styles to themes or add styles to the component.
Styles must be added directly to a ts file:
import { STYLES as SLIDER_STYLES } from '@alyle/ui/slider';
import {
STYLES as CROPPER_STYLES,
LyImageCropper,
ImgCropperConfig,
ImgCropperEvent,
ImgCropperErrorEvent
} from '@alyle/ui/image-cropper';
const STYLES = (_theme: ThemeVariables, ref: ThemeRef) => {
ref.renderStyleSheet(SLIDER_STYLES);
ref.renderStyleSheet(CROPPER_STYLES);
const slider = ref.selectorsOf(SLIDER_STYLES);
const cropper = ref.selectorsOf(CROPPER_STYLES);
return {
root: lyl `{
${cropper.root} {
max-width: 320px
height: 320px
}
${cropper.area} {
// styles for cropper area
}
}`,
sliderContainer: lyl `{
position: relative
${slider.root} {
position: absolute
left: 0
right: 0
margin: auto
top: -32px
}
}`,
slider: lyl `{
padding: 1em
}`
};
};
@Component({
...
providers: [
StyleRenderer
]
})
export class CropperDialog implements WithStyles, AfterViewInit {
readonly classes = this.sRenderer.renderSheet(STYLES, 'root');
The second parameter of
renderSheet
is the class name that will be added to this component.
About Customization:
Tnx for the explanation , one more question
return {
root: lyl `{
${cropper.root} {
max-width: 320px
height: 320px
}
${cropper.area} {
// styles for cropper area
}
}`,
sliderContainer: lyl `{
position: relative
${slider.root} {
position: absolute
left: 0
right: 0
margin: auto
top: -32px
}
}`,
slider: lyl `{
padding: 1em
}`
};
where the keys in this object are coming from? sliderContainer
, slider
? are they classnames?
Yes, they are keys that can be created with any name to use in components, for example:
<div [className]="classes.sliderContainer">
<div [className]="classes.slider">
classes.sliderContainer
returns a classname, you can also use it with [class]
. [className]
& [ngClass]
.
How can you do the same for a hover effect?
How can you do the same for a hover effect?
I think it would be something like this but I am not sure and have not tested it.
return {
slider: lyl `{
&:hover {
}
}`
};
Thanks a lot!
Bug, feature request, or proposal:
I am not sure if this is a bug or a mistake on my side!
What is the expected behavior?
components have the same classes in
--prod
build that they have in development enviromentWhat is the current behavior?
classes on components are changed in production
Which versions of Angular, AlyleUI, OS, TypeScript, browsers are affected?
Version of
@alyle/ui@
: ^10.3.0Example
I had this styles for my image cropper
With this html
I added the
custom-cropper
class so that my coworker can style the component as needed, this worked just fine in development environment, but after we deployed the code to production--prod
this custom styles stopped workingmy local dev run has these classes :
LyImageCropper-root-af cropper-ab
but the prod run has these :af ab
?? what am I missing here?https://stackoverflow.com/questions/64569216/customizing-alyle-ui-component-styles