Rename focused and hovered pseudo classes to focus and hover
Since that's how it's defined for HTML as well.
This commit is contained in:
parent
c412f00840
commit
3964dfda5b
@ -32,7 +32,7 @@ class UpdateContext:
|
||||
Context used when updating items (Presentation's).
|
||||
|
||||
Style contains the base style, no style alterations due to view state
|
||||
(focused, hovered, etc.).
|
||||
(focus, hover, etc.).
|
||||
"""
|
||||
|
||||
style: Style
|
||||
@ -59,7 +59,7 @@ class StyledItem:
|
||||
Wrapper to allow style information to be retrieved.
|
||||
|
||||
For convenience, a view can be added. The view will provide
|
||||
pseudo-classes for the item (focused, hovered, etc.)
|
||||
pseudo-classes for the item (focus, hover, etc.)
|
||||
"""
|
||||
|
||||
def __init__(self, item: gaphas.Item, view: Optional[gaphas.View] = None):
|
||||
@ -88,8 +88,8 @@ class StyledItem:
|
||||
item = self.item
|
||||
return (
|
||||
"active" if item in view.selected_items else "",
|
||||
"focused" if item is view.focused_item else "",
|
||||
"hovered" if item is view.hovered_item else "",
|
||||
"focus" if item is view.focused_item else "",
|
||||
"hover" if item is view.hovered_item else "",
|
||||
"drop" if item is view.dropzone_item else "",
|
||||
)
|
||||
return ()
|
||||
|
@ -115,7 +115,7 @@ def compile_pseudo_class_selector(selector: parser.PseudoClassSelector):
|
||||
name = selector.name
|
||||
if name == "empty":
|
||||
return lambda el: not next(el.children(), 0)
|
||||
elif name in ("root", "hovered", "focused", "active", "drop"):
|
||||
elif name in ("root", "hover", "focus", "active", "drop"):
|
||||
return lambda el: name in el.state()
|
||||
else:
|
||||
raise parser.SelectorError("Unknown pseudo-class", name)
|
||||
|
@ -197,7 +197,7 @@ def test_empty_pseudo_selector_with_name():
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"state", ["root", "hovered", "focused", "active", "drop"],
|
||||
"state", ["root", "hover", "focus", "active", "drop"],
|
||||
)
|
||||
def test_hovered_pseudo_selector(state):
|
||||
|
||||
@ -211,27 +211,27 @@ def test_hovered_pseudo_selector(state):
|
||||
|
||||
|
||||
def test_is_pseudo_selector():
|
||||
css = "classitem:is(:hovered, :active) {}"
|
||||
css = "classitem:is(:hover, :active) {}"
|
||||
|
||||
(selector, specificity), payload = next(parse_style_sheet(css))
|
||||
|
||||
assert selector(Node("classitem", state=("hovered",)))
|
||||
assert selector(Node("classitem", state=("hover",)))
|
||||
assert selector(Node("classitem", state=("active",)))
|
||||
assert selector(Node("classitem", state=("hovered", "active")))
|
||||
assert selector(Node("classitem", state=("hover", "active")))
|
||||
assert specificity == (0, 1, 1)
|
||||
assert not selector(Node("classitem"))
|
||||
|
||||
|
||||
def test_not_pseudo_selector():
|
||||
css = "classitem:not(:hovered) {}"
|
||||
css = "classitem:not(:hover) {}"
|
||||
|
||||
(selector, specificity), payload = next(parse_style_sheet(css))
|
||||
|
||||
assert selector(Node("classitem"))
|
||||
assert selector(Node("classitem", state=("active")))
|
||||
assert specificity == (0, 1, 1)
|
||||
assert not selector(Node("classitem", state=("hovered",)))
|
||||
assert not selector(Node("classitem", state=("hovered", "active")))
|
||||
assert not selector(Node("classitem", state=("hover",)))
|
||||
assert not selector(Node("classitem", state=("hover", "active")))
|
||||
|
||||
|
||||
def test_has_pseudo_selector():
|
||||
@ -279,12 +279,10 @@ def test_has_pseudo_selector_with_combinator_is_not_supported():
|
||||
|
||||
|
||||
def test_has_and_is_selector():
|
||||
css = "node:has(:is(:hovered)) {}"
|
||||
css = "node:has(:is(:hover)) {}"
|
||||
|
||||
(selector, specificity), payload = next(parse_style_sheet(css))
|
||||
|
||||
assert selector(
|
||||
Node(
|
||||
"node", children=[Node("foo", children=[Node("bar", state=("hovered",))])],
|
||||
)
|
||||
Node("node", children=[Node("foo", children=[Node("bar", state=("hover",))])],)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user