Extends StyleableModel
props
CssRulePropertiesopt
any (optional, default{}
)
selectors
Array<Selector> Array of selectorsstyle
Object Object containing style definitionsselectorsAdd
String? Additional string css selectorsatRuleType
String? Type of at-rule, eg.media
, 'font-face'mediaText
String? At-rule value, eg.(max-width: 1000px)
singleAtRule
Boolean? This property is used only on at-rules, like 'page' or 'font-face', where the block containes only style declarationsstate
String? State of the rule, eg:hover
,focused
important
(Boolean | Array<String>)? If true, sets!important
on all properties. You can also pass an array to specify properties on which use importantstylable
Boolean? Indicates if the rule is stylable from the editor[Device]: device.html[State]: state.html[Component]: component.html
Returns the at-rule statement when exists, eg. @media (...)
, @keyframes
const cssRule = editor.Css.setRule('.class1', { color: 'red' }, {
atRuleType: 'media',
atRuleParams: '(min-width: 500px)'
});
cssRule.getAtRule(); // "@media (min-width: 500px)"
Returns String
Return selectors of the rule as a string
const cssRule = editor.Css.setRule('.class1:hover', { color: 'red' });
cssRule.selectorsToString(); // ".class1:hover"
cssRule.selectorsToString({ skipState: true }); // ".class1"
Returns String
Get declaration block (without the at-rule statement)
opts
Object Options (same as inselectorsToString
) (optional, default{}
)
const cssRule = editor.Css.setRule('.class1', { color: 'red' }, {
atRuleType: 'media',
atRuleParams: '(min-width: 500px)'
});
cssRule.getDeclaration() // ".class1{color:red;}"
Returns String
Get the Device the rule is related to.
const device = rule.getDevice();
console.log(device?.getName());
Returns ([Device] | null)
Get the State the rule is related to.
const state = rule.getState();
console.log(state?.getLabel());
Returns ([State] | null)
Returns the related Component (valid only for component-specific rules).
const cmp = rule.getComponent();
console.log(cmp?.toHTML());
Returns ([Component] | null)
Return the CSS string of the rule
opts
Object Options (same as ingetDeclaration
) (optional, default{}
)
const cssRule = editor.Css.setRule('.class1', { color: 'red' }, {
atRuleType: 'media',
atRuleParams: '(min-width: 500px)'
});
cssRule.toCSS() // "@media (min-width: 500px){.class1{color:red;}}"
Returns String CSS string