Skip to content
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

[Tidy] Remove CSS classes to position image #919

Merged
merged 20 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
45f0994
Remove img CSS classes
huong-li-nguyen Dec 4, 2024
617b1e6
Add changelog
huong-li-nguyen Dec 4, 2024
c9664e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
6f5d9e1
Merge branch 'main' into tidy/remove-custom-img-css
huong-li-nguyen Dec 4, 2024
9b458f9
Update vizro-core/changelog.d/20241204_135618_huong_li_nguyen_remove_…
huong-li-nguyen Dec 4, 2024
bcf21c8
Remove `icon-top`
huong-li-nguyen Dec 4, 2024
8d63b8e
Merge branch 'tidy/remove-custom-img-css' of https://github.com/mckin…
huong-li-nguyen Dec 4, 2024
fc6f180
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
287ef61
Update docs
huong-li-nguyen Dec 4, 2024
6df08f1
Merge branch 'tidy/remove-custom-img-css' of https://github.com/mckin…
huong-li-nguyen Dec 4, 2024
2647ecd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
b41defc
Update images
huong-li-nguyen Dec 4, 2024
0c659e3
Merge branch 'tidy/remove-custom-img-css' of https://github.com/mckin…
huong-li-nguyen Dec 4, 2024
c0d4b68
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
55929a5
Update vizro-core/docs/pages/tutorials/explore-components.md
huong-li-nguyen Dec 4, 2024
395d4e4
Update vizro-core/docs/pages/user-guides/card-button.md
huong-li-nguyen Dec 4, 2024
db51d40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
09062fe
Remove title argument inside chart
huong-li-nguyen Dec 4, 2024
343cdd4
Merge branch 'tidy/remove-custom-img-css' of https://github.com/mckin…
huong-li-nguyen Dec 4, 2024
c37c2ae
Remove double-call
huong-li-nguyen Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨

- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->

### Removed

- Remove built-in CSS shortcuts `#floating-*` to float images. These can still be provided manually. ([#919](https://github.com/mckinsey/vizro/pull/919))


<!--
### Added

- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Changed

- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Deprecated

- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Fixed

- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Security

- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
70 changes: 14 additions & 56 deletions vizro-core/docs/pages/user-guides/card-button.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,18 @@ Use the following pre-defined URL hashes in your image path to apply Vizro's def

#### To float the image next to the text:

- floating-left: `![](my_image.png#floating-left)`
- floating-right: `![](my_image.png#floating-right)`
- floating-center: `![](my_image.png#floating-center)`
To float an image for example to the right of the text, use the `src` attribute as a CSS selector. Follow these steps:

1. Add a hash (#) to the image URL, e.g., `![](assets/images/continents/europe.svg#my-image)`
1. Target that hash in your custom CSS file `img[src*="#my-image"] { float: right; }`

!!! example "Card with floating image"
=== "images.css"
```css
img[src*="#my-image"] {
width: 120px;
height: 120px;
float: right;
}
```

Expand All @@ -349,7 +351,7 @@ Use the following pre-defined URL hashes in your image path to apply Vizro's def
text="""
### My card with floating image!

![](assets/images/continents/europe.svg#my-image#floating-right)
![](assets/images/continents/europe.svg#my-image)

Commodi repudiandae consequuntur voluptatum laborum numquam blanditiis harum quisquam eius sed odit.

Expand Down Expand Up @@ -381,7 +383,7 @@ Use the following pre-defined URL hashes in your image path to apply Vizro's def
pages:
- components:
- text: |
![](assets/images/continents/europe.svg#my-image#floating-right)
![](assets/images/continents/europe.svg#my-image)

Commodi repudiandae consequuntur voluptatum laborum numquam blanditiis harum quisquam eius sed odit.

Expand All @@ -402,63 +404,19 @@ Use the following pre-defined URL hashes in your image path to apply Vizro's def
=== "Result"
[![CardImageFloating]][cardimagefloating]

#### Card with icon

- default icon styling (`icon-top`): `![](my_image.png#icon-top)`

!!! example "Card with icon"
=== "app.py"
```{.python pycafe-link}
import vizro.models as vm
huong-li-nguyen marked this conversation as resolved.
Show resolved Hide resolved
from vizro import Vizro

page = vm.Page(
title="Card with icon",
components=[
vm.Card(
text="""
![](https://raw.githubusercontent.com/mckinsey/vizro/d24a6f0d4efdf3c47392458e64b190fa1f92b2a7/vizro-core/docs/assets/images/hypotheses.svg#icon-top)

### Card Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut fringilla dictum lacus eget fringilla.
Maecenas in various nibh, quis venenatis nulla. Integer et libero ultrices, scelerisque velit sed.
""",
),
],
)

dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()
```

=== "app.yaml"
```yaml
# Still requires a .py to add data to the data manager and parse YAML configuration
# See from_yaml example
pages:
- components:
- text: |
![](assets/images/icons/hypotheses.svg#icon-top)

### Card Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut fringilla dictum lacus eget fringilla.
Maecenas in various nibh, quis venenatis nulla. Integer et libero ultrices, scelerisque velit sed.
type: card
title: Card with icon
```

=== "Result"
[![CardIcon]][cardicon]

### Make an icon responsive to theme switch

To make an icon responsive to the theme switch, override the value of the [`filter` CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/filter). The `filter` CSS property lets you add visual effects to elements using different functions. In our example, we're using the `--inverse-color` CSS variable from the Vizro theme. It uses the CSS `invert()` function to flip the color of the icon when you switch themes. Note that this only works if your initial icon has a white fill color. If your icon is not white, you can change its color by adding `fill="white"` to the SVG code. Assign the predefined CSS variable `--inverse-color` to the `filter` property of your selected icon.
To make an icon responsive to theme switching, override its
[`filter` CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/filter). In this example, we use the
`--fill-icon-image-card` CSS variable from the `vizro-bootstrap` CSS file. It leverages the `invert()` function to
flip the icon's color during a theme switch.

This approach works if your icon initially has a white fill color. If not, modify the SVG code by adding `fill="white"`.

```css
img[src*="#my-image"] {
filter: var(--inverse-color);
filter: var(--fill-icon-image-card);
}
```

Expand Down
6 changes: 6 additions & 0 deletions vizro-core/examples/dev/assets/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@
img#banner {
height: 16px;
}

img[src*="icon-top"] {
filter: var(--fill-icon-image-card);
height: 36px;
width: 36px;
}
21 changes: 0 additions & 21 deletions vizro-core/src/vizro/static/css/images.css

This file was deleted.

Loading