-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Set up shared package for components and utilities #13486
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
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
121bc76
move common components to site_shared package
schultek aedd5a2
move tutorial and do some cleanup
schultek 0f19aaa
move styles
schultek 78d9219
adapt tutorial components for shared use
schultek 01243a8
share styles_hash_builder
schultek 068b597
remove unneeded deps
schultek eda96e2
move shared components in subfolder
schultek 99ab0d2
create shared dash layout
schultek 752434c
move extensions to shared package
schultek f7ebc71
fix formatting
schultek 2b74570
add reset styles and banner component to shared package
schultek ed4f1e6
Merge branch 'main' into feat/site_shared
schultek bb0d4ed
apply review
schultek c4007b2
add readme
schultek 64db575
Merge branch 'main' into feat/site_shared
parlough 377473d
Standardize on consistent, YAML-based banner
parlough 6d63215
Clean up new README formatting
parlough ee6bc94
Account for review suggestions
parlough 52d5303
Merge branch 'main' into feat/site_shared
parlough a81822c
Encode rather than escape stylesheet hash
parlough ecc0789
Update sidenav handling for changes on main
parlough 33679ad
Consistently end SCSS files with extra new line
parlough 311f56d
Misc clean up
parlough 9e7fc51
Auto organize imports
parlough 91e9489
Reformat with latest beta
parlough 8d09e24
Inline remaining member of site-specific util file
parlough e0ecac3
Consolidate analytics usage to shared version
parlough 88b7126
Clean up print override styles
parlough 67757be
Remove some now unused styles
parlough 9abc493
Move progress ring styles like the other components
parlough e2d90db
Clean up progress ring implementation a bit
parlough c15106a
Add missing license headers
parlough 0fb54a0
Account for suggestions from review
parlough c690bd8
Minor comment cleanup
parlough 43cbaff
Organize content extensions into a single library
parlough 81a9bb3
Slightly restructure shared analytics library
parlough 40b6222
Move dash_layout to src directory
parlough ef07e6c
Separate out web-utils from other utils
parlough bd1d3f2
Move slugify to src directory
parlough 700c53b
Replace web_platform with standard web_util library
parlough a395fb3
Clean up package:site_shared/util.dart
parlough ad806da
Separate ID from name for browser OS
parlough File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # site_shared | ||
|
|
||
| This package is the core library containing | ||
| shared logic, UI components, and the design system for | ||
| the Dart and Flutter documentation sites. | ||
|
|
||
| It provides a centralized location for APIs, | ||
| user interface elements, and logic intended for use by | ||
| both the `dart.dev` and `docs.flutter.dev` websites. | ||
| Using a shared package ensures a consistent design language and | ||
| feature set across Dart and Flutter web documentation platforms. | ||
|
|
||
| ## What's included | ||
|
|
||
| The `site_shared` package provides several key capabilities to | ||
| build documentation websites using Dart, Jaspr, and Jaspr Content: | ||
|
|
||
| - **UI components** (`lib/components`): | ||
| Reusable, modular components built for use across documentation pages. | ||
| - **Common components** (`lib/components/common`): | ||
| Everyday UI elements such as breadcrumbs, buttons, code blocks, and more. | ||
| - **Layout components** (`lib/components/layout`): | ||
| Structural layout elements like theme switchers, | ||
| site switchers, banners, and menu toggles. | ||
| - **Interactive components**: | ||
| Integrations such as Dartpad (`lib/components/dartpad`), | ||
| tutorials, and user client-side feedback tools. | ||
| - **Markdown extensions and processors** (`lib/extensions`): | ||
| Custom processors that hook into the Dart Markdown parser to | ||
| extend its default syntax and behavior, such as `attribute_processor.dart`. | ||
| - **Core styles** (`lib/_sass`): | ||
| The shared base styles and component-specific SCSS styling. | ||
| These resources define the unified visual identity used by both websites. | ||
| - **Utilities and builders** (`lib/src`): | ||
| Reusable logic for code syntax highlighting (`lib/src/highlight`), | ||
| analytics integrations (`lib/src/analytics`), | ||
| builders (`lib/src/builders`), and various helper utilities. | ||
|
|
||
| ## Goals | ||
|
|
||
| The primary aims of this shared package are to: | ||
|
|
||
| 1. Streamline styling and standardize UI component implementation | ||
| across our various websites. | ||
| 1. Prevent code duplication between the | ||
| `dart-lang/site-www` and `flutter/website` repositories. | ||
| 1. Establish a robust codebase that can be | ||
| updated, maintained, and improved in a unified way. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| include: package:analysis_defaults/analysis.yaml | ||
|
|
||
| formatter: | ||
| trailing_commas: preserve |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| builders: | ||
| stylesHashBuilder: | ||
| import: "package:site_shared/src/builders/styles_hash_builder.dart" | ||
| builder_factories: ["stylesHashBuilder"] | ||
| build_extensions: | ||
| "web/assets/css/main.css": | ||
| - "lib/src/style_hash.dart" | ||
| auto_apply: dependents | ||
| build_to: source | ||
| required_inputs: | ||
| - ".css" | ||
| defaults: | ||
| dev_options: | ||
| fixed_hash: true |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,7 +173,7 @@ | |
| } | ||
| } | ||
|
|
||
| &.install-card { | ||
| &.install-card { | ||
| gap: 0.25rem; | ||
|
|
||
| .card-leading { | ||
|
|
||
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
packages/site_shared/lib/_sass/components/_menu-toggle.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Toggle between menu and close buttons if sidenav is open or not. | ||
| body:not(.sidenav-closed) #menu-toggle { | ||
| @media (min-width: 1024px) { | ||
| display: none; | ||
| } | ||
| } | ||
|
|
||
| #menu-toggle span.material-symbols { | ||
| &:first-child { | ||
| display: inline; | ||
| } | ||
|
|
||
| &:last-child { | ||
| display: none; | ||
| } | ||
| } | ||
|
|
||
| body.open_menu #menu-toggle span.material-symbols { | ||
| &:first-child { | ||
| display: none; | ||
| } | ||
|
|
||
| &:last-child { | ||
| display: inline; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
packages/site_shared/lib/_sass/components/_progress-ring.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| .progress-ring { | ||
| circle { | ||
| fill: none; | ||
| stroke-linecap: round; | ||
| } | ||
|
|
||
| .ring-inactive { | ||
| stroke: var(--site-inset-borderColor); | ||
| } | ||
|
|
||
| .ring-active { | ||
| stroke: var(--site-primary-color); | ||
| } | ||
| } |
File renamed without changes.
2 changes: 0 additions & 2 deletions
2
.../lib/_sass/components/_site-switcher.scss → .../lib/_sass/components/_site-switcher.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| @use '../base/mixins'; | ||
|
|
||
| #site-switcher { | ||
| position: relative; | ||
|
|
||
|
|
||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Copyright 2026 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| export 'src/analytics/analytics.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ class Button extends StatelessComponent { | |
| const Button({ | ||
| super.key, | ||
| this.icon, | ||
| this.trailingIcon, | ||
| this.href, | ||
| this.content, | ||
| this.style = ButtonStyle.text, | ||
|
|
@@ -30,6 +31,7 @@ class Button extends StatelessComponent { | |
| final String? title; | ||
| final ButtonStyle style; | ||
| final String? icon; | ||
| final String? trailingIcon; | ||
| final String? id; | ||
| final String? href; | ||
| final Map<String, String> attributes; | ||
|
|
@@ -48,14 +50,16 @@ class Button extends StatelessComponent { | |
|
|
||
| final mergedClasses = [ | ||
| style.cssClass, | ||
| if (icon != null && content == null) 'icon-button', | ||
| if ((icon != null || trailingIcon != null) && content == null) | ||
| 'icon-button', | ||
| ...?classes, | ||
| ].toClasses; | ||
|
|
||
| final children = <Component>[ | ||
| if (icon case final iconId?) MaterialIcon(iconId), | ||
| if (content case final contentText?) | ||
| asRaw ? RawText(contentText) : .text(contentText), | ||
|
Contributor
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. |
||
| if (trailingIcon case final iconId?) MaterialIcon(iconId), | ||
| ]; | ||
|
|
||
| if (href case final href?) { | ||
|
|
@@ -90,17 +94,3 @@ enum ButtonStyle { | |
| ButtonStyle.text => 'text-button', | ||
| }; | ||
| } | ||
|
|
||
| class SegmentedButton extends StatelessComponent { | ||
| const SegmentedButton({ | ||
| super.key, | ||
| required this.children, | ||
| }); | ||
|
|
||
| final List<Component> children; | ||
|
|
||
| @override | ||
| Component build(BuildContext context) { | ||
| return span(classes: ['segmented-button'].toClasses, children); | ||
| } | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,14 @@ import '../button.dart'; | |
| /// The cookie banner to show on a user's first time visiting the site. | ||
| @client | ||
| final class CookieNotice extends StatefulComponent { | ||
| const CookieNotice({super.key}); | ||
| const CookieNotice({ | ||
| super.key, | ||
| required this.host, | ||
| this.alwaysDarkMode = false, | ||
| }); | ||
|
|
||
| final String host; | ||
| final bool alwaysDarkMode; | ||
|
|
||
| @override | ||
| State<CookieNotice> createState() => _CookieNoticeState(); | ||
|
|
@@ -60,13 +67,16 @@ final class _CookieNoticeState extends State<CookieNotice> { | |
| Component build(BuildContext context) { | ||
| return section( | ||
| id: 'cookie-notice', | ||
| classes: [if (showNotice) 'show'].toClasses, | ||
| classes: [ | ||
| if (showNotice) 'show', | ||
| if (component.alwaysDarkMode) 'always-dark-mode', | ||
| ].toClasses, | ||
| attributes: {'data-nosnippet': 'true'}, | ||
| [ | ||
| div(classes: 'container', [ | ||
| const p([ | ||
| p([ | ||
| .text( | ||
|
Contributor
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. |
||
| 'docs.flutter.dev uses cookies from Google to deliver and ' | ||
| '${component.host} uses cookies from Google to deliver and ' | ||
| 'enhance the quality of its services and to analyze traffic.', | ||
| ), | ||
| ]), | ||
|
parlough marked this conversation as resolved.
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.