-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: styles #81
Feat: styles #81
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { Fragment, h, Host } from '@builder.io/qwik'; | ||
import { ElementFixture, trigger } from '../../testing/element_fixture'; | ||
import { expectDOM } from '../../testing/expect-dom'; | ||
import { expectDOM } from '../../testing/expect-dom.unit'; | ||
import { qComponent } from '../component/q-component.public'; | ||
import { qHook } from '../component/qrl-hook.public'; | ||
import { qrlStyles } from '../component/qrl-styles'; | ||
import { qStyles, styleKey } from '../component/qrl-styles'; | ||
import { TEST_CONFIG } from '../util/test_config'; | ||
import { Async, JSXPromise, PromiseValue } from './jsx/async.public'; | ||
import { Slot } from './jsx/slot.public'; | ||
|
@@ -304,14 +304,18 @@ describe('q-render', () => { | |
expectRendered( | ||
<hello-world | ||
on:q-render={HelloWorld.onRender} | ||
q:style={HelloWorld.styles as any} | ||
q:sstyle={HelloWorld_styles} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scoped Style. Not loving it, but for now until we figure out something better. |
||
class={HelloWorld.styleHostClass as any} | ||
> | ||
<span class={HelloWorld.styleClass as any}> | ||
{'Hello'} {'World'} | ||
</span> | ||
</hello-world> | ||
); | ||
const style = fixture.document.querySelector( | ||
'style[q\\:style="' + styleKey(HelloWorld_styles) + '"]' | ||
)!; | ||
expect(style.textContent).toEqual('span { color: red; }'); | ||
}); | ||
}); | ||
}); | ||
|
@@ -323,9 +327,10 @@ describe('q-render', () => { | |
////////////////////////////////////////////////////////////////////////////////////////// | ||
// Hello World | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
const HelloWorld_styles = qStyles<any>(`span { color: red; }`); | ||
export const HelloWorld = qComponent<{ name?: string }, { salutation: string }>({ | ||
tagName: 'hello-world', | ||
styles: qrlStyles<any>('./mock.unit.css#ABC123'), | ||
styles: HelloWorld_styles, | ||
onMount: qHook(() => ({ salutation: 'Hello' })), | ||
onRender: qHook((props, state) => { | ||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
export function hashCode(text: string, hash: number = 0) { | ||
if (text.length === 0) return hash; | ||
for (let i = 0; i < text.length; i++) { | ||
const chr = text.charCodeAt(i); | ||
hash = ((hash << 5) - hash) + chr; | ||
hash |= 0; // Convert to 32bit integer | ||
} | ||
return Number(Math.abs(hash)).toString(36); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,12 @@ export const enum AttributeMarker { | |
/** | ||
* Component Styles. | ||
*/ | ||
ComponentStyles = 'q:style', | ||
ComponentStyles = 'q:sstyle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok guess it's correct, but why the change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we can have both scoped and unscoped styles. |
||
|
||
/** | ||
* Unscoped Component Styles. | ||
*/ | ||
ComponentUnscopedStyles = 'q:ustyle', | ||
|
||
/** | ||
* Component style host prefix | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
/�/g
?