@buildcanada/charts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +8 -0
- package/README.md +113 -0
- package/package.json +137 -0
- package/src/components/BodyPortal/BodyPortal.tsx +40 -0
- package/src/components/Button/Button.scss +110 -0
- package/src/components/Button/Button.tsx +101 -0
- package/src/components/Checkbox.scss +93 -0
- package/src/components/Checkbox.tsx +47 -0
- package/src/components/ExpandableToggle/ExpandableToggle.scss +123 -0
- package/src/components/ExpandableToggle/ExpandableToggle.tsx +60 -0
- package/src/components/GrapherTabIcon.tsx +156 -0
- package/src/components/GrapherTrendArrow.scss +16 -0
- package/src/components/GrapherTrendArrow.tsx +30 -0
- package/src/components/Halo/Halo.tsx +44 -0
- package/src/components/LabeledSwitch/LabeledSwitch.scss +109 -0
- package/src/components/LabeledSwitch/LabeledSwitch.tsx +62 -0
- package/src/components/MarkdownTextWrap/MarkdownTextWrap.tsx +1173 -0
- package/src/components/OverlayHeader.scss +18 -0
- package/src/components/OverlayHeader.tsx +29 -0
- package/src/components/RadioButton.scss +69 -0
- package/src/components/RadioButton.tsx +42 -0
- package/src/components/SimpleMarkdownText.tsx +89 -0
- package/src/components/TextInput.scss +17 -0
- package/src/components/TextInput.tsx +19 -0
- package/src/components/TextWrap/TextWrap.tsx +361 -0
- package/src/components/TextWrap/TextWrapUtils.ts +32 -0
- package/src/components/closeButton/CloseButton.scss +40 -0
- package/src/components/closeButton/CloseButton.tsx +27 -0
- package/src/components/index.ts +70 -0
- package/src/components/loadingIndicator/LoadingIndicator.scss +40 -0
- package/src/components/loadingIndicator/LoadingIndicator.tsx +28 -0
- package/src/components/markdown/remarkPlainLinks.ts +36 -0
- package/src/components/reactUtil.ts +20 -0
- package/src/components/stubs/CodeSnippet.tsx +19 -0
- package/src/components/stubs/DataCitation.tsx +16 -0
- package/src/components/stubs/IndicatorKeyData.tsx +45 -0
- package/src/components/stubs/IndicatorProcessing.tsx +15 -0
- package/src/components/stubs/IndicatorSources.tsx +15 -0
- package/src/components/styles/colors.scss +113 -0
- package/src/components/styles/mixins.scss +630 -0
- package/src/components/styles/typography.scss +579 -0
- package/src/components/styles/util.scss +89 -0
- package/src/components/styles/variables.scss +208 -0
- package/src/config/ChartsConfig.ts +163 -0
- package/src/config/ChartsProvider.tsx +157 -0
- package/src/config/index.ts +20 -0
- package/src/core-table/CoreTable.ts +1355 -0
- package/src/core-table/CoreTableColumns.ts +973 -0
- package/src/core-table/CoreTableUtils.ts +793 -0
- package/src/core-table/ErrorValues.ts +73 -0
- package/src/core-table/OwidTable.ts +1175 -0
- package/src/core-table/OwidTableSynthesizers.ts +272 -0
- package/src/core-table/OwidTableUtil.ts +76 -0
- package/src/core-table/Transforms.ts +484 -0
- package/src/core-table/index.ts +82 -0
- package/src/explorer/ColumnGrammar.ts +217 -0
- package/src/explorer/Explorer.sample.ts +212 -0
- package/src/explorer/Explorer.scss +148 -0
- package/src/explorer/Explorer.tsx +1283 -0
- package/src/explorer/ExplorerConstants.ts +85 -0
- package/src/explorer/ExplorerControls.scss +156 -0
- package/src/explorer/ExplorerControls.tsx +210 -0
- package/src/explorer/ExplorerDecisionMatrix.ts +471 -0
- package/src/explorer/ExplorerGrammar.ts +161 -0
- package/src/explorer/ExplorerProgram.ts +568 -0
- package/src/explorer/ExplorerUtils.ts +59 -0
- package/src/explorer/GrapherGrammar.ts +387 -0
- package/src/explorer/gridLang/GrammarUtils.ts +121 -0
- package/src/explorer/gridLang/GridCell.ts +298 -0
- package/src/explorer/gridLang/GridLangConstants.ts +255 -0
- package/src/explorer/gridLang/GridProgram.ts +311 -0
- package/src/explorer/gridLang/readme.md +17 -0
- package/src/explorer/index.ts +69 -0
- package/src/explorer/readme.md +19 -0
- package/src/explorer/urlMigrations/CO2UrlMigration.ts +46 -0
- package/src/explorer/urlMigrations/CovidUrlMigration.ts +37 -0
- package/src/explorer/urlMigrations/EnergyUrlMigration.ts +41 -0
- package/src/explorer/urlMigrations/ExplorerPageUrlMigrationSpec.ts +12 -0
- package/src/explorer/urlMigrations/ExplorerUrlMigrationUtils.ts +45 -0
- package/src/explorer/urlMigrations/ExplorerUrlMigrations.ts +33 -0
- package/src/explorer/urlMigrations/LegacyCovidUrlMigration.ts +144 -0
- package/src/explorer/urlMigrations/readme.md +39 -0
- package/src/grapher/axis/Axis.ts +973 -0
- package/src/grapher/axis/AxisConfig.ts +179 -0
- package/src/grapher/axis/AxisViews.tsx +597 -0
- package/src/grapher/barCharts/DiscreteBarChart.tsx +728 -0
- package/src/grapher/barCharts/DiscreteBarChartConstants.ts +60 -0
- package/src/grapher/barCharts/DiscreteBarChartHelpers.ts +338 -0
- package/src/grapher/barCharts/DiscreteBarChartState.ts +354 -0
- package/src/grapher/barCharts/DiscreteBarChartThumbnail.tsx +34 -0
- package/src/grapher/captionedChart/CaptionedChart.scss +61 -0
- package/src/grapher/captionedChart/CaptionedChart.tsx +523 -0
- package/src/grapher/captionedChart/Logos.tsx +141 -0
- package/src/grapher/captionedChart/LogosSVG.tsx +16 -0
- package/src/grapher/captionedChart/StaticChartRasterizer.tsx +178 -0
- package/src/grapher/captionedChart/assets/buildcanada-logo-square.svg +15 -0
- package/src/grapher/captionedChart/assets/buildcanada-logo.svg +15 -0
- package/src/grapher/captionedChart/assets/canadaspends.svg +7 -0
- package/src/grapher/captionedChart/readme.md +14 -0
- package/src/grapher/chart/Chart.tsx +62 -0
- package/src/grapher/chart/ChartAreaContent.tsx +172 -0
- package/src/grapher/chart/ChartDimension.ts +121 -0
- package/src/grapher/chart/ChartInterface.ts +83 -0
- package/src/grapher/chart/ChartManager.ts +113 -0
- package/src/grapher/chart/ChartTabs.ts +178 -0
- package/src/grapher/chart/ChartTypeMap.tsx +158 -0
- package/src/grapher/chart/ChartTypeSwitcher.tsx +26 -0
- package/src/grapher/chart/ChartUtils.tsx +364 -0
- package/src/grapher/chart/DimensionSlot.ts +45 -0
- package/src/grapher/chart/StaticChartWrapper.tsx +94 -0
- package/src/grapher/chart/guidedChartUtils.ts +82 -0
- package/src/grapher/color/BinningStrategies.ts +484 -0
- package/src/grapher/color/BinningStrategyEqualSizeBins.ts +132 -0
- package/src/grapher/color/BinningStrategyLogarithmic.ts +121 -0
- package/src/grapher/color/CategoricalColorAssigner.ts +97 -0
- package/src/grapher/color/ColorBrewerSchemes.ts +80 -0
- package/src/grapher/color/ColorConstants.ts +20 -0
- package/src/grapher/color/ColorScale.ts +339 -0
- package/src/grapher/color/ColorScaleBin.ts +147 -0
- package/src/grapher/color/ColorScaleConfig.ts +204 -0
- package/src/grapher/color/ColorScheme.ts +137 -0
- package/src/grapher/color/ColorSchemes.ts +149 -0
- package/src/grapher/color/ColorUtils.ts +86 -0
- package/src/grapher/color/CustomSchemes.ts +1772 -0
- package/src/grapher/color/readme.md +84 -0
- package/src/grapher/comparisonLine/ComparisonLine.tsx +31 -0
- package/src/grapher/comparisonLine/ComparisonLineConstants.ts +11 -0
- package/src/grapher/comparisonLine/ComparisonLineGenerator.ts +60 -0
- package/src/grapher/comparisonLine/ComparisonLineHelpers.ts +10 -0
- package/src/grapher/comparisonLine/CustomComparisonLine.tsx +159 -0
- package/src/grapher/comparisonLine/VerticalComparisonLine.tsx +208 -0
- package/src/grapher/controls/ActionButtons.scss +97 -0
- package/src/grapher/controls/ActionButtons.tsx +453 -0
- package/src/grapher/controls/CommandPalette.scss +50 -0
- package/src/grapher/controls/CommandPalette.tsx +74 -0
- package/src/grapher/controls/ContentSwitchers.scss +93 -0
- package/src/grapher/controls/ContentSwitchers.tsx +238 -0
- package/src/grapher/controls/Controls.scss +158 -0
- package/src/grapher/controls/DataTableFilterDropdown.scss +7 -0
- package/src/grapher/controls/DataTableFilterDropdown.tsx +168 -0
- package/src/grapher/controls/DataTableSearchField.scss +3 -0
- package/src/grapher/controls/DataTableSearchField.tsx +76 -0
- package/src/grapher/controls/Dropdown.scss +252 -0
- package/src/grapher/controls/Dropdown.tsx +235 -0
- package/src/grapher/controls/EntitySelectionToggle.tsx +135 -0
- package/src/grapher/controls/MapRegionDropdown.scss +3 -0
- package/src/grapher/controls/MapRegionDropdown.tsx +104 -0
- package/src/grapher/controls/MapResetButton.tsx +115 -0
- package/src/grapher/controls/MapZoomDropdown.scss +9 -0
- package/src/grapher/controls/MapZoomDropdown.tsx +270 -0
- package/src/grapher/controls/MapZoomToSelectionButton.tsx +87 -0
- package/src/grapher/controls/SearchField.scss +78 -0
- package/src/grapher/controls/SearchField.tsx +63 -0
- package/src/grapher/controls/SettingsMenu.scss +191 -0
- package/src/grapher/controls/SettingsMenu.tsx +399 -0
- package/src/grapher/controls/ShareMenu.scss +58 -0
- package/src/grapher/controls/ShareMenu.tsx +304 -0
- package/src/grapher/controls/SortIcon.tsx +39 -0
- package/src/grapher/controls/VerticalScrollContainer.tsx +263 -0
- package/src/grapher/controls/controlsRow/ControlsRow.tsx +168 -0
- package/src/grapher/controls/dropdown-icons.scss +4 -0
- package/src/grapher/controls/entityPicker/EntityPicker.scss +255 -0
- package/src/grapher/controls/entityPicker/EntityPicker.tsx +816 -0
- package/src/grapher/controls/entityPicker/EntityPickerConstants.ts +23 -0
- package/src/grapher/controls/globalEntitySelector/GlobalEntitySelector.scss +129 -0
- package/src/grapher/controls/globalEntitySelector/GlobalEntitySelector.tsx +463 -0
- package/src/grapher/controls/globalEntitySelector/GlobalEntitySelectorConstants.ts +3 -0
- package/src/grapher/controls/globalEntitySelector/readme.md +17 -0
- package/src/grapher/controls/settings/AbsRelToggle.tsx +64 -0
- package/src/grapher/controls/settings/AxisScaleToggle.tsx +53 -0
- package/src/grapher/controls/settings/FacetStrategySelector.tsx +110 -0
- package/src/grapher/controls/settings/FacetYDomainToggle.tsx +51 -0
- package/src/grapher/controls/settings/NoDataAreaToggle.tsx +38 -0
- package/src/grapher/controls/settings/ZoomToggle.tsx +36 -0
- package/src/grapher/core/EntitiesByRegionType.ts +174 -0
- package/src/grapher/core/EntityCodes.ts +19 -0
- package/src/grapher/core/EntityUrlBuilder.ts +200 -0
- package/src/grapher/core/FetchingGrapher.tsx +156 -0
- package/src/grapher/core/Grapher.tsx +760 -0
- package/src/grapher/core/GrapherAnalytics.ts +229 -0
- package/src/grapher/core/GrapherConstants.ts +173 -0
- package/src/grapher/core/GrapherState.tsx +3659 -0
- package/src/grapher/core/GrapherUrl.ts +184 -0
- package/src/grapher/core/GrapherUrlMigrations.ts +29 -0
- package/src/grapher/core/GrapherUseHelpers.tsx +147 -0
- package/src/grapher/core/LegacyToOwidTable.ts +841 -0
- package/src/grapher/core/grapher.entry.ts +5 -0
- package/src/grapher/core/grapher.scss +257 -0
- package/src/grapher/core/loadGrapherTableHelpers.ts +116 -0
- package/src/grapher/core/loadVariable.ts +104 -0
- package/src/grapher/core/relatedQuestion.ts +12 -0
- package/src/grapher/core/typography.scss +206 -0
- package/src/grapher/dataTable/DataTable.sample.ts +206 -0
- package/src/grapher/dataTable/DataTable.scss +249 -0
- package/src/grapher/dataTable/DataTable.tsx +1332 -0
- package/src/grapher/dataTable/DataTableConstants.ts +186 -0
- package/src/grapher/entitySelector/EntitySelector.scss +255 -0
- package/src/grapher/entitySelector/EntitySelector.tsx +1838 -0
- package/src/grapher/facet/FacetChart.tsx +943 -0
- package/src/grapher/facet/FacetChartConstants.ts +24 -0
- package/src/grapher/facet/FacetChartUtils.ts +51 -0
- package/src/grapher/facet/FacetMap.tsx +604 -0
- package/src/grapher/facet/FacetMapConstants.ts +23 -0
- package/src/grapher/facet/readme.md +13 -0
- package/src/grapher/focus/FocusArray.ts +79 -0
- package/src/grapher/footer/Footer.scss +63 -0
- package/src/grapher/footer/Footer.tsx +809 -0
- package/src/grapher/footer/FooterManager.ts +44 -0
- package/src/grapher/fullScreen/FullScreen.scss +11 -0
- package/src/grapher/fullScreen/FullScreen.tsx +61 -0
- package/src/grapher/header/Header.scss +35 -0
- package/src/grapher/header/Header.tsx +372 -0
- package/src/grapher/header/HeaderManager.ts +28 -0
- package/src/grapher/index.ts +157 -0
- package/src/grapher/interaction/InteractionState.ts +60 -0
- package/src/grapher/legend/HorizontalColorLegends.tsx +923 -0
- package/src/grapher/legend/LegendInteractionState.ts +40 -0
- package/src/grapher/legend/VerticalColorLegend.tsx +295 -0
- package/src/grapher/lineCharts/LineChart.tsx +968 -0
- package/src/grapher/lineCharts/LineChartConstants.ts +89 -0
- package/src/grapher/lineCharts/LineChartHelpers.ts +184 -0
- package/src/grapher/lineCharts/LineChartState.ts +394 -0
- package/src/grapher/lineCharts/LineChartThumbnail.tsx +437 -0
- package/src/grapher/lineCharts/Lines.tsx +258 -0
- package/src/grapher/lineLegend/LineLegend.tsx +723 -0
- package/src/grapher/lineLegend/LineLegendConstants.ts +9 -0
- package/src/grapher/lineLegend/LineLegendFilterAlgorithms.ts +143 -0
- package/src/grapher/lineLegend/LineLegendHelpers.ts +253 -0
- package/src/grapher/lineLegend/LineLegendTypes.ts +32 -0
- package/src/grapher/mapCharts/CanadaTopology.ts +17922 -0
- package/src/grapher/mapCharts/ChoroplethGlobe.tsx +949 -0
- package/src/grapher/mapCharts/ChoroplethMap.tsx +662 -0
- package/src/grapher/mapCharts/GeoFeatures.ts +184 -0
- package/src/grapher/mapCharts/GlobeController.ts +496 -0
- package/src/grapher/mapCharts/MapAnnotationPlacements.json +1040 -0
- package/src/grapher/mapCharts/MapAnnotationPlacements.ts +31 -0
- package/src/grapher/mapCharts/MapAnnotations.ts +723 -0
- package/src/grapher/mapCharts/MapChart.sample.ts +59 -0
- package/src/grapher/mapCharts/MapChart.scss +5 -0
- package/src/grapher/mapCharts/MapChart.tsx +720 -0
- package/src/grapher/mapCharts/MapChartConstants.ts +260 -0
- package/src/grapher/mapCharts/MapChartState.ts +416 -0
- package/src/grapher/mapCharts/MapChartThumbnail.tsx +25 -0
- package/src/grapher/mapCharts/MapComponents.tsx +338 -0
- package/src/grapher/mapCharts/MapConfig.ts +156 -0
- package/src/grapher/mapCharts/MapHelpers.ts +181 -0
- package/src/grapher/mapCharts/MapProjections.ts +49 -0
- package/src/grapher/mapCharts/MapSparkline.tsx +257 -0
- package/src/grapher/mapCharts/MapTooltip.scss +49 -0
- package/src/grapher/mapCharts/MapTooltip.tsx +409 -0
- package/src/grapher/mapCharts/MapTopology.ts +1766 -0
- package/src/grapher/mapCharts/d3-bboxCollide.js +204 -0
- package/src/grapher/mapCharts/d3-geo-projection.ts +198 -0
- package/src/grapher/modal/DownloadIcons.tsx +39 -0
- package/src/grapher/modal/DownloadModal.scss +300 -0
- package/src/grapher/modal/DownloadModal.tsx +1226 -0
- package/src/grapher/modal/EmbedModal.scss +40 -0
- package/src/grapher/modal/EmbedModal.tsx +160 -0
- package/src/grapher/modal/EntitySelectorModal.tsx +59 -0
- package/src/grapher/modal/Modal.scss +31 -0
- package/src/grapher/modal/Modal.tsx +90 -0
- package/src/grapher/modal/ModalHeader.scss +12 -0
- package/src/grapher/modal/ModalHeader.tsx +16 -0
- package/src/grapher/modal/SourcesDescriptions.scss +87 -0
- package/src/grapher/modal/SourcesDescriptions.tsx +89 -0
- package/src/grapher/modal/SourcesKeyDataTable.scss +49 -0
- package/src/grapher/modal/SourcesKeyDataTable.tsx +87 -0
- package/src/grapher/modal/SourcesModal.scss +301 -0
- package/src/grapher/modal/SourcesModal.tsx +568 -0
- package/src/grapher/noDataModal/NoDataModal.tsx +125 -0
- package/src/grapher/scatterCharts/ConnectedScatterLegend.tsx +143 -0
- package/src/grapher/scatterCharts/MultiColorPolyline.tsx +129 -0
- package/src/grapher/scatterCharts/NoDataSection.scss +14 -0
- package/src/grapher/scatterCharts/NoDataSection.tsx +56 -0
- package/src/grapher/scatterCharts/ScatterPlotChart.tsx +792 -0
- package/src/grapher/scatterCharts/ScatterPlotChartConstants.ts +157 -0
- package/src/grapher/scatterCharts/ScatterPlotChartState.ts +678 -0
- package/src/grapher/scatterCharts/ScatterPlotChartThumbnail.tsx +155 -0
- package/src/grapher/scatterCharts/ScatterPlotTooltip.tsx +560 -0
- package/src/grapher/scatterCharts/ScatterPoints.tsx +153 -0
- package/src/grapher/scatterCharts/ScatterPointsWithLabels.tsx +708 -0
- package/src/grapher/scatterCharts/ScatterSizeLegend.tsx +327 -0
- package/src/grapher/scatterCharts/ScatterUtils.ts +265 -0
- package/src/grapher/scatterCharts/Triangle.tsx +41 -0
- package/src/grapher/schema/README.md +33 -0
- package/src/grapher/schema/defaultGrapherConfig.ts +100 -0
- package/src/grapher/schema/grapher-schema.009.yaml +781 -0
- package/src/grapher/schema/migrations/helpers.ts +58 -0
- package/src/grapher/schema/migrations/migrate.ts +75 -0
- package/src/grapher/schema/migrations/migrations.ts +158 -0
- package/src/grapher/selection/MapSelectionArray.ts +99 -0
- package/src/grapher/selection/SelectionArray.ts +71 -0
- package/src/grapher/selection/readme.md +16 -0
- package/src/grapher/sidePanel/SidePanel.scss +10 -0
- package/src/grapher/sidePanel/SidePanel.tsx +23 -0
- package/src/grapher/slideInDrawer/SlideInDrawer.scss +57 -0
- package/src/grapher/slideInDrawer/SlideInDrawer.tsx +125 -0
- package/src/grapher/slideshowController/SlideShowController.tsx +43 -0
- package/src/grapher/slideshowController/readme.md +7 -0
- package/src/grapher/slopeCharts/MarkX.tsx +45 -0
- package/src/grapher/slopeCharts/Slope.tsx +102 -0
- package/src/grapher/slopeCharts/SlopeChart.tsx +1152 -0
- package/src/grapher/slopeCharts/SlopeChartConstants.ts +33 -0
- package/src/grapher/slopeCharts/SlopeChartHelpers.ts +73 -0
- package/src/grapher/slopeCharts/SlopeChartState.ts +392 -0
- package/src/grapher/slopeCharts/SlopeChartThumbnail.tsx +368 -0
- package/src/grapher/stackedCharts/AbstractStackedChartState.ts +370 -0
- package/src/grapher/stackedCharts/MarimekkoBars.tsx +190 -0
- package/src/grapher/stackedCharts/MarimekkoBarsForOneEntity.tsx +168 -0
- package/src/grapher/stackedCharts/MarimekkoChart.tsx +1144 -0
- package/src/grapher/stackedCharts/MarimekkoChartConstants.ts +112 -0
- package/src/grapher/stackedCharts/MarimekkoChartHelpers.ts +21 -0
- package/src/grapher/stackedCharts/MarimekkoChartState.ts +465 -0
- package/src/grapher/stackedCharts/MarimekkoChartThumbnail.tsx +168 -0
- package/src/grapher/stackedCharts/MarimekkoInternalLabels.tsx +124 -0
- package/src/grapher/stackedCharts/StackedAreaChart.tsx +678 -0
- package/src/grapher/stackedCharts/StackedAreaChartState.ts +34 -0
- package/src/grapher/stackedCharts/StackedAreaChartThumbnail.tsx +215 -0
- package/src/grapher/stackedCharts/StackedAreas.tsx +223 -0
- package/src/grapher/stackedCharts/StackedBarChart.tsx +619 -0
- package/src/grapher/stackedCharts/StackedBarChartState.ts +80 -0
- package/src/grapher/stackedCharts/StackedBarChartThumbnail.tsx +220 -0
- package/src/grapher/stackedCharts/StackedBarSegment.tsx +87 -0
- package/src/grapher/stackedCharts/StackedBars.tsx +102 -0
- package/src/grapher/stackedCharts/StackedConstants.ts +109 -0
- package/src/grapher/stackedCharts/StackedDiscreteBarChart.tsx +270 -0
- package/src/grapher/stackedCharts/StackedDiscreteBarChartState.ts +296 -0
- package/src/grapher/stackedCharts/StackedDiscreteBarChartThumbnail.tsx +27 -0
- package/src/grapher/stackedCharts/StackedDiscreteBars.tsx +648 -0
- package/src/grapher/stackedCharts/StackedUtils.ts +142 -0
- package/src/grapher/tabs/Tabs.scss +169 -0
- package/src/grapher/tabs/Tabs.tsx +54 -0
- package/src/grapher/tabs/TabsWithDropdown.scss +62 -0
- package/src/grapher/tabs/TabsWithDropdown.tsx +114 -0
- package/src/grapher/testData/OwidTestData.sample.ts +273 -0
- package/src/grapher/testData/OwidTestData.ts +64 -0
- package/src/grapher/timeline/TimelineComponent.scss +139 -0
- package/src/grapher/timeline/TimelineComponent.tsx +658 -0
- package/src/grapher/timeline/TimelineController.ts +368 -0
- package/src/grapher/timeline/readme.md +7 -0
- package/src/grapher/tooltip/Tooltip.scss +510 -0
- package/src/grapher/tooltip/Tooltip.tsx +294 -0
- package/src/grapher/tooltip/TooltipContents.tsx +383 -0
- package/src/grapher/tooltip/TooltipProps.ts +123 -0
- package/src/grapher/tooltip/TooltipState.ts +81 -0
- package/src/grapher/verticalLabels/VerticalLabels.tsx +31 -0
- package/src/grapher/verticalLabels/VerticalLabelsState.ts +154 -0
- package/src/index.ts +226 -0
- package/src/styles/charts.scss +15 -0
- package/src/types/NominalType.ts +30 -0
- package/src/types/OwidOrigin.ts +18 -0
- package/src/types/OwidSource.ts +9 -0
- package/src/types/OwidVariable.ts +133 -0
- package/src/types/OwidVariableDisplayConfigInterface.ts +49 -0
- package/src/types/analyticsTypes.ts +54 -0
- package/src/types/dbTypes/Tags.ts +11 -0
- package/src/types/domainTypes/Archive.ts +139 -0
- package/src/types/domainTypes/Author.ts +28 -0
- package/src/types/domainTypes/ContentGraph.ts +76 -0
- package/src/types/domainTypes/CoreTableTypes.ts +305 -0
- package/src/types/domainTypes/DeployStatus.ts +23 -0
- package/src/types/domainTypes/Layout.ts +34 -0
- package/src/types/domainTypes/Posts.ts +34 -0
- package/src/types/domainTypes/Search.ts +299 -0
- package/src/types/domainTypes/Site.ts +8 -0
- package/src/types/domainTypes/StaticViz.ts +64 -0
- package/src/types/domainTypes/Toc.ts +11 -0
- package/src/types/domainTypes/Tombstone.ts +19 -0
- package/src/types/domainTypes/Various.ts +79 -0
- package/src/types/gdocTypes/Gdoc.ts +280 -0
- package/src/types/grapherTypes/BinningStrategyTypes.ts +46 -0
- package/src/types/grapherTypes/GrapherConstants.ts +53 -0
- package/src/types/grapherTypes/GrapherTypes.ts +743 -0
- package/src/types/index.ts +316 -0
- package/src/types/wordpressTypes/WordpressTypes.ts +9 -0
- package/src/utils/Bounds.ts +439 -0
- package/src/utils/BrowserUtils.ts +12 -0
- package/src/utils/FuzzySearch.ts +74 -0
- package/src/utils/MultiDimDataPageConfig.ts +31 -0
- package/src/utils/OwidVariable.ts +82 -0
- package/src/utils/PointVector.ts +97 -0
- package/src/utils/PromiseCache.ts +36 -0
- package/src/utils/PromiseSwitcher.ts +52 -0
- package/src/utils/TimeBounds.ts +130 -0
- package/src/utils/Tippy.tsx +57 -0
- package/src/utils/Util.ts +2369 -0
- package/src/utils/archival/archivalDate.ts +48 -0
- package/src/utils/dayjs.ts +32 -0
- package/src/utils/formatValue.ts +242 -0
- package/src/utils/grapherConfigUtils.ts +81 -0
- package/src/utils/image.ts +225 -0
- package/src/utils/index.ts +318 -0
- package/src/utils/isPresent.ts +5 -0
- package/src/utils/metadataHelpers.ts +329 -0
- package/src/utils/persistable/Persistable.ts +82 -0
- package/src/utils/persistable/readme.md +50 -0
- package/src/utils/regions.json +5635 -0
- package/src/utils/regions.ts +463 -0
- package/src/utils/serializers.ts +16 -0
- package/src/utils/string.ts +42 -0
- package/src/utils/urls/Url.ts +195 -0
- package/src/utils/urls/UrlMigration.ts +10 -0
- package/src/utils/urls/UrlUtils.ts +54 -0
- package/src/utils/urls/readme.md +90 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2024 Our World in Data
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# @buildcanada/charts
|
|
2
|
+
|
|
3
|
+
Part of the [Build Canada Design System](https://github.com/BuildCanada/bcds) monorepo.
|
|
4
|
+
|
|
5
|
+
A configurable data visualization library for creating interactive charts. Extracted from [Our World in Data's](https://ourworldindata.org) Grapher.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @buildcanada/charts
|
|
11
|
+
# or
|
|
12
|
+
bun add @buildcanada/charts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Peer Dependencies
|
|
16
|
+
|
|
17
|
+
This library requires the following peer dependencies:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"react": "^19.0.0",
|
|
22
|
+
"react-dom": "^19.0.0",
|
|
23
|
+
"mobx": "^6.13.0",
|
|
24
|
+
"mobx-react": "^7.6.0"
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import {
|
|
32
|
+
ChartsProvider,
|
|
33
|
+
Grapher,
|
|
34
|
+
GrapherState,
|
|
35
|
+
GRAPHER_CHART_TYPES,
|
|
36
|
+
DimensionProperty,
|
|
37
|
+
createOwidTestDataset,
|
|
38
|
+
legacyToOwidTableAndDimensionsWithMandatorySlug,
|
|
39
|
+
} from "@buildcanada/charts"
|
|
40
|
+
import "@buildcanada/charts/styles.css"
|
|
41
|
+
|
|
42
|
+
// Define your data
|
|
43
|
+
const myData = [
|
|
44
|
+
{ year: 2020, entity: { id: 1, name: "Canada" }, value: 100 },
|
|
45
|
+
{ year: 2021, entity: { id: 1, name: "Canada" }, value: 120 },
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
const metadata = { id: 1, display: { name: "My Metric" } }
|
|
49
|
+
const dimensions = [{ variableId: 1, property: DimensionProperty.y }]
|
|
50
|
+
|
|
51
|
+
const dataset = createOwidTestDataset([{ data: myData, metadata }])
|
|
52
|
+
const table = legacyToOwidTableAndDimensionsWithMandatorySlug(dataset, dimensions, {})
|
|
53
|
+
|
|
54
|
+
const grapherState = new GrapherState({
|
|
55
|
+
title: "My Chart",
|
|
56
|
+
chartTypes: [GRAPHER_CHART_TYPES.LineChart],
|
|
57
|
+
dimensions,
|
|
58
|
+
})
|
|
59
|
+
grapherState.inputTable = table
|
|
60
|
+
|
|
61
|
+
function App() {
|
|
62
|
+
return (
|
|
63
|
+
<ChartsProvider>
|
|
64
|
+
<div style={{ width: "800px", height: "600px" }}>
|
|
65
|
+
<Grapher grapherState={grapherState} />
|
|
66
|
+
</div>
|
|
67
|
+
</ChartsProvider>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Documentation
|
|
73
|
+
|
|
74
|
+
- **[Data Loading Guide](docs/DATA_LOADING_GUIDE.md)** - Complete guide on loading CSV/JSON data
|
|
75
|
+
- **[Publishing Guide](docs/PUBLISHING.md)** - How to publish to npm
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
bun install # Install dependencies
|
|
81
|
+
bun run storybook # Run Storybook on port 6006
|
|
82
|
+
bun run build # Build Storybook for production
|
|
83
|
+
bun test # Run tests
|
|
84
|
+
bun run typecheck # TypeScript check
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Components
|
|
88
|
+
|
|
89
|
+
### Grapher
|
|
90
|
+
|
|
91
|
+
The main charting component supporting multiple visualization types:
|
|
92
|
+
- Line charts
|
|
93
|
+
- Bar charts (discrete and stacked)
|
|
94
|
+
- Scatter plots
|
|
95
|
+
- World and regional maps
|
|
96
|
+
- Stacked area charts
|
|
97
|
+
- Slope charts
|
|
98
|
+
- Marimekko charts
|
|
99
|
+
|
|
100
|
+
### Explorer
|
|
101
|
+
|
|
102
|
+
A data explorer that wraps Grapher and adds additional controls for exploring complex datasets.
|
|
103
|
+
|
|
104
|
+
## Architecture
|
|
105
|
+
|
|
106
|
+
- Built with **React 19** and **MobX 6** for state management
|
|
107
|
+
- Uses TC-39 stage 3 decorators
|
|
108
|
+
- TypeScript throughout
|
|
109
|
+
- SCSS for styling with BEM conventions
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@buildcanada/charts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A configurable data visualization library for creating interactive charts. Extracted from Our World in Data's Grapher.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.ts",
|
|
11
|
+
"import": "./src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"./styles.css": "./src/styles/charts.scss",
|
|
14
|
+
"./src/styles/charts.scss": "./src/styles/charts.scss",
|
|
15
|
+
"./src/*": "./src/*"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"src",
|
|
19
|
+
"!src/**/*.test.ts",
|
|
20
|
+
"!src/**/*.test.tsx",
|
|
21
|
+
"!src/**/*.stories.tsx"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/BuildCanada/bcds.git",
|
|
26
|
+
"directory": "packages/charts"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/BuildCanada/bcds/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/BuildCanada/bcds#readme",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "storybook build -o storybook-static",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest",
|
|
43
|
+
"storybook": "storybook dev -p 6006",
|
|
44
|
+
"serve-storybook": "serve storybook-static -p 6006"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"charts",
|
|
48
|
+
"data-visualization",
|
|
49
|
+
"react",
|
|
50
|
+
"d3",
|
|
51
|
+
"grapher",
|
|
52
|
+
"explorer"
|
|
53
|
+
],
|
|
54
|
+
"author": "Build Canada",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"mobx": "^6.13.0",
|
|
58
|
+
"mobx-react": "^7.6.0",
|
|
59
|
+
"react": "^19.0.0",
|
|
60
|
+
"react-dom": "^19.0.0"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
|
64
|
+
"@fortawesome/free-brands-svg-icons": "^6.7.2",
|
|
65
|
+
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
|
66
|
+
"@fortawesome/react-fontawesome": "^0.2.2",
|
|
67
|
+
"@tippyjs/react": "^4.2.6",
|
|
68
|
+
"@turf/boolean-intersects": "^7.2.0",
|
|
69
|
+
"@turf/center": "^7.2.0",
|
|
70
|
+
"classnames": "^2.5.1",
|
|
71
|
+
"colorbrewer": "^1.3.0",
|
|
72
|
+
"d3": "^7.9.0",
|
|
73
|
+
"dayjs": "^1.11.11",
|
|
74
|
+
"fparser": "^3.1.0",
|
|
75
|
+
"fuzzysort": "^3.1.0",
|
|
76
|
+
"indefinite": "^2.5.1",
|
|
77
|
+
"js-cookie": "^3.0.5",
|
|
78
|
+
"lodash-es": "^4.17.21",
|
|
79
|
+
"mdast-util-find-and-replace": "^3.0.2",
|
|
80
|
+
"mdast-util-from-markdown": "^2.0.2",
|
|
81
|
+
"mousetrap": "^1.6.5",
|
|
82
|
+
"papaparse": "^5.5.3",
|
|
83
|
+
"react-aria-components": "^1.13.0",
|
|
84
|
+
"react-flip-toolkit": "^7.2.4",
|
|
85
|
+
"react-markdown": "^10.1.0",
|
|
86
|
+
"react-move": "^6.5.0",
|
|
87
|
+
"react-select": "^5.10.2",
|
|
88
|
+
"remeda": "^2.32.0",
|
|
89
|
+
"simple-statistics": "^7.8.8",
|
|
90
|
+
"string-pixel-width": "^1.10.0",
|
|
91
|
+
"striptags": "^3.2.0",
|
|
92
|
+
"topojson-client": "^3.1.0",
|
|
93
|
+
"ts-pattern": "^5.8.0",
|
|
94
|
+
"unist-util-visit": "^5.0.0",
|
|
95
|
+
"url-join": "^5.0.0",
|
|
96
|
+
"url-parse": "^1.5.10",
|
|
97
|
+
"url-slug": "^4.0.1",
|
|
98
|
+
"uuidv7": "^1.0.1",
|
|
99
|
+
"versor": "^0.2.0"
|
|
100
|
+
},
|
|
101
|
+
"devDependencies": {
|
|
102
|
+
"@storybook/addon-docs": "^10.1.11",
|
|
103
|
+
"@storybook/react": "^10.1.11",
|
|
104
|
+
"@storybook/react-vite": "^10.1.11",
|
|
105
|
+
"@testing-library/dom": "^10.4.1",
|
|
106
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
107
|
+
"@testing-library/react": "^16.3.0",
|
|
108
|
+
"@types/colorbrewer": "^1.0.29",
|
|
109
|
+
"@types/d3": "^7.4.3",
|
|
110
|
+
"@types/geojson": "^7946.0.10",
|
|
111
|
+
"@types/indefinite": "^2.3.4",
|
|
112
|
+
"@types/js-cookie": "^3.0.6",
|
|
113
|
+
"@types/lodash-es": "^4",
|
|
114
|
+
"@types/mousetrap": "^1.6.9",
|
|
115
|
+
"@types/papaparse": "^5.3.16",
|
|
116
|
+
"@types/react": "^19.2.2",
|
|
117
|
+
"@types/react-dom": "^19.2.2",
|
|
118
|
+
"@types/string-pixel-width": "^1.7.2",
|
|
119
|
+
"@types/topojson-client": "^3.1.1",
|
|
120
|
+
"@types/url-parse": "^1.4.8",
|
|
121
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
122
|
+
"eslint": "^9.37.0",
|
|
123
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
124
|
+
"happy-dom": "^20.1.0",
|
|
125
|
+
"jsdom": "^27.4.0",
|
|
126
|
+
"mobx": "^6.13.7",
|
|
127
|
+
"mobx-react": "^7.6.0",
|
|
128
|
+
"react": "^19.2.0",
|
|
129
|
+
"react-dom": "^19.2.0",
|
|
130
|
+
"sass": "^1.77.0",
|
|
131
|
+
"serve": "^14.2.5",
|
|
132
|
+
"storybook": "^10.1.11",
|
|
133
|
+
"typescript": "~5.9.2",
|
|
134
|
+
"vite": "^6.0.0",
|
|
135
|
+
"vitest": "^4.0.15"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import ReactDOM from "react-dom"
|
|
3
|
+
|
|
4
|
+
interface BodyPortalProps {
|
|
5
|
+
children: React.ReactNode
|
|
6
|
+
containerClassName?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Renders a component on Body instead of inside the current tree.
|
|
11
|
+
* See https://react.dev/reference/react-dom/createPortal
|
|
12
|
+
*/
|
|
13
|
+
export class BodyPortal extends React.Component<BodyPortalProps> {
|
|
14
|
+
private element: HTMLDivElement | null = null
|
|
15
|
+
|
|
16
|
+
override componentDidMount(): void {
|
|
17
|
+
if (typeof document !== "undefined") {
|
|
18
|
+
this.element = document.createElement("div")
|
|
19
|
+
if (this.props.containerClassName)
|
|
20
|
+
this.element.className = this.props.containerClassName
|
|
21
|
+
|
|
22
|
+
document.body.appendChild(this.element)
|
|
23
|
+
// Force a re-render now that `this.el` is available for the portal
|
|
24
|
+
this.forceUpdate()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override componentWillUnmount(): void {
|
|
29
|
+
// Remove the element from the body if it was added
|
|
30
|
+
if (this.element && this.element.parentNode === document.body) {
|
|
31
|
+
document.body.removeChild(this.element)
|
|
32
|
+
}
|
|
33
|
+
this.element = null // Clean up the reference
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override render(): React.ReactPortal | null {
|
|
37
|
+
if (!this.element) return null
|
|
38
|
+
return ReactDOM.createPortal(this.props.children, this.element)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
.owid-btn {
|
|
2
|
+
@include body-3-medium;
|
|
3
|
+
padding: 8.5px 24px;
|
|
4
|
+
border: 1px solid transparent;
|
|
5
|
+
border-radius: 0;
|
|
6
|
+
text-align: center;
|
|
7
|
+
display: block;
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
|
|
10
|
+
&.owid-btn--icon-only {
|
|
11
|
+
padding: 4.5px 9px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&:disabled {
|
|
15
|
+
cursor: default;
|
|
16
|
+
|
|
17
|
+
&.owid-btn--solid-blue,
|
|
18
|
+
&.owid-btn--solid-dark-blue,
|
|
19
|
+
&.owid-btn--solid-light-blue,
|
|
20
|
+
&.owid-btn--solid-vermillion {
|
|
21
|
+
color: $blue-50;
|
|
22
|
+
background-color: $blue-10;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&.owid-btn--outline-vermillion,
|
|
26
|
+
&.owid-btn--outline-white {
|
|
27
|
+
color: $blue-40;
|
|
28
|
+
border-color: $blue-40;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
svg {
|
|
33
|
+
font-size: 0.75rem;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.owid-btn--icon-right {
|
|
38
|
+
margin-left: 0.5rem;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.owid-btn--icon-left {
|
|
42
|
+
margin-right: 0.5rem;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.owid-btn--solid-vermillion {
|
|
46
|
+
background-color: $vermillion;
|
|
47
|
+
color: #fff;
|
|
48
|
+
|
|
49
|
+
&:hover {
|
|
50
|
+
background-color: $accent-vermillion;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.owid-btn--outline-vermillion {
|
|
55
|
+
border-color: $vermillion;
|
|
56
|
+
color: $vermillion;
|
|
57
|
+
|
|
58
|
+
&:hover {
|
|
59
|
+
border-color: $accent-vermillion;
|
|
60
|
+
color: $accent-vermillion;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.owid-btn--solid-blue {
|
|
65
|
+
background-color: $blue-60;
|
|
66
|
+
color: #fff;
|
|
67
|
+
|
|
68
|
+
&:hover {
|
|
69
|
+
background-color: $blue-90;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.owid-btn--solid-dark-blue {
|
|
74
|
+
background-color: $blue-95;
|
|
75
|
+
color: #fff;
|
|
76
|
+
|
|
77
|
+
&:hover {
|
|
78
|
+
background-color: #164377;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.owid-btn--solid-light-blue {
|
|
83
|
+
background-color: $blue-20;
|
|
84
|
+
color: $blue-90;
|
|
85
|
+
|
|
86
|
+
&:hover {
|
|
87
|
+
background-color: $blue-10;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.owid-btn--outline-white {
|
|
92
|
+
background-color: transparent;
|
|
93
|
+
border-color: $white;
|
|
94
|
+
color: $white;
|
|
95
|
+
|
|
96
|
+
&:hover {
|
|
97
|
+
background-color: $white;
|
|
98
|
+
color: $blue-90;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.owid-btn--outline-light-blue {
|
|
103
|
+
border-color: $blue-20;
|
|
104
|
+
color: $blue-90;
|
|
105
|
+
|
|
106
|
+
&:hover {
|
|
107
|
+
background-color: $white;
|
|
108
|
+
color: $blue-90;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import cx from "classnames"
|
|
2
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
|
3
|
+
import { IconDefinition, faArrowRight } from "@fortawesome/free-solid-svg-icons"
|
|
4
|
+
|
|
5
|
+
type ButtonCommonProps = {
|
|
6
|
+
text?: string
|
|
7
|
+
className?: string
|
|
8
|
+
style?: React.CSSProperties
|
|
9
|
+
theme:
|
|
10
|
+
| "solid-vermillion"
|
|
11
|
+
| "solid-blue"
|
|
12
|
+
| "solid-dark-blue"
|
|
13
|
+
| "solid-light-blue"
|
|
14
|
+
| "outline-vermillion"
|
|
15
|
+
| "outline-light-blue"
|
|
16
|
+
| "outline-white"
|
|
17
|
+
/** Set to null to hide the icon */
|
|
18
|
+
icon?: IconDefinition | null
|
|
19
|
+
iconPosition?: "left" | "right"
|
|
20
|
+
dataTrackNote?: string
|
|
21
|
+
disabled?: boolean
|
|
22
|
+
ariaLabel?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type WithHrefProps = {
|
|
26
|
+
href: string
|
|
27
|
+
onClick?: never
|
|
28
|
+
type?: never
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type WithOnClickProps = {
|
|
32
|
+
onClick?: () => void
|
|
33
|
+
href?: never
|
|
34
|
+
type?: "button" | "submit"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type ButtonProps =
|
|
38
|
+
| (ButtonCommonProps & WithHrefProps)
|
|
39
|
+
| (ButtonCommonProps & WithOnClickProps)
|
|
40
|
+
|
|
41
|
+
export const Button = ({
|
|
42
|
+
theme = "solid-vermillion",
|
|
43
|
+
className,
|
|
44
|
+
style,
|
|
45
|
+
href,
|
|
46
|
+
onClick,
|
|
47
|
+
text,
|
|
48
|
+
ariaLabel,
|
|
49
|
+
type = "button",
|
|
50
|
+
icon = faArrowRight,
|
|
51
|
+
iconPosition = "right",
|
|
52
|
+
dataTrackNote,
|
|
53
|
+
disabled,
|
|
54
|
+
}: ButtonProps) => {
|
|
55
|
+
const classes = cx("owid-btn", `owid-btn--${theme}`, className, {
|
|
56
|
+
"owid-btn--icon-only": icon && !text,
|
|
57
|
+
})
|
|
58
|
+
const content = (
|
|
59
|
+
<>
|
|
60
|
+
{iconPosition === "left" && icon && (
|
|
61
|
+
<FontAwesomeIcon
|
|
62
|
+
className={cx({ "owid-btn--icon-left": text })}
|
|
63
|
+
icon={icon}
|
|
64
|
+
/>
|
|
65
|
+
)}
|
|
66
|
+
{text && <span>{text}</span>}
|
|
67
|
+
{iconPosition !== "left" && icon && (
|
|
68
|
+
<FontAwesomeIcon
|
|
69
|
+
className={cx({ "owid-btn--icon-right": text })}
|
|
70
|
+
icon={icon}
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
</>
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if (href) {
|
|
77
|
+
const aProps = {
|
|
78
|
+
href: disabled ? undefined : href,
|
|
79
|
+
className: classes,
|
|
80
|
+
style,
|
|
81
|
+
"data-track-note": dataTrackNote,
|
|
82
|
+
onClick: disabled
|
|
83
|
+
? (e: React.MouseEvent) => e.preventDefault()
|
|
84
|
+
: undefined,
|
|
85
|
+
"aria-label": ariaLabel,
|
|
86
|
+
"aria-disabled": disabled,
|
|
87
|
+
}
|
|
88
|
+
return <a {...aProps}>{content}</a>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const buttonProps = {
|
|
92
|
+
type,
|
|
93
|
+
className: classes,
|
|
94
|
+
style,
|
|
95
|
+
onClick,
|
|
96
|
+
"aria-label": ariaLabel,
|
|
97
|
+
"data-track-note": dataTrackNote,
|
|
98
|
+
disabled,
|
|
99
|
+
}
|
|
100
|
+
return <button {...buttonProps}>{content}</button>
|
|
101
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
.checkbox {
|
|
2
|
+
$checkbox-size: 16px;
|
|
3
|
+
|
|
4
|
+
$light-stroke: $gray-30;
|
|
5
|
+
$hover-stroke: $blue-30;
|
|
6
|
+
$active-fill: $blue-30;
|
|
7
|
+
|
|
8
|
+
position: relative;
|
|
9
|
+
|
|
10
|
+
label {
|
|
11
|
+
margin: 0; // style leak in admin
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
input {
|
|
15
|
+
position: absolute;
|
|
16
|
+
opacity: 0;
|
|
17
|
+
left: 0;
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
pointer-events: none;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.custom {
|
|
23
|
+
position: absolute;
|
|
24
|
+
left: 0;
|
|
25
|
+
top: 0;
|
|
26
|
+
content: " ";
|
|
27
|
+
width: $checkbox-size;
|
|
28
|
+
height: $checkbox-size;
|
|
29
|
+
|
|
30
|
+
background: white;
|
|
31
|
+
pointer-events: none;
|
|
32
|
+
border-radius: 2px;
|
|
33
|
+
border: 1px solid $light-stroke;
|
|
34
|
+
color: #fff;
|
|
35
|
+
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: center;
|
|
39
|
+
|
|
40
|
+
svg {
|
|
41
|
+
font-size: 10px;
|
|
42
|
+
padding-left: 0.75px;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
input:focus-visible + .custom {
|
|
47
|
+
outline: 2px solid $controls-color;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
input:active + .custom {
|
|
51
|
+
background: $active-fill;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
input:checked + .custom {
|
|
55
|
+
background: $active-fill;
|
|
56
|
+
border-color: $active-fill;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
input:checked:active + .custom {
|
|
60
|
+
background: white;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
input:disabled {
|
|
64
|
+
+ .custom {
|
|
65
|
+
background: $blue-10;
|
|
66
|
+
border-color: $blue-20;
|
|
67
|
+
color: $blue-50;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&:active + .custom {
|
|
71
|
+
background: $blue-10;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
~ .label {
|
|
75
|
+
color: $blue-50;
|
|
76
|
+
cursor: not-allowed;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.label {
|
|
81
|
+
@include grapher_label-2-regular;
|
|
82
|
+
padding-left: $checkbox-size + 8px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
user-select: none;
|
|
85
|
+
color: $dark-text;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&:hover {
|
|
89
|
+
input:not(:checked) + .custom {
|
|
90
|
+
border-color: $hover-stroke;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
|
3
|
+
import { faCheck } from "@fortawesome/free-solid-svg-icons"
|
|
4
|
+
import cx from "classnames"
|
|
5
|
+
|
|
6
|
+
export const Checkbox = ({
|
|
7
|
+
className,
|
|
8
|
+
checked,
|
|
9
|
+
onChange,
|
|
10
|
+
label,
|
|
11
|
+
disabled,
|
|
12
|
+
id,
|
|
13
|
+
"data-test": testHook,
|
|
14
|
+
}: {
|
|
15
|
+
className?: string
|
|
16
|
+
checked: boolean
|
|
17
|
+
onChange: React.ChangeEventHandler<HTMLInputElement>
|
|
18
|
+
label: React.ReactNode
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
id?: string
|
|
21
|
+
"data-test"?: string
|
|
22
|
+
}) => {
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
className={cx(
|
|
26
|
+
"checkbox",
|
|
27
|
+
{ "checkbox--disabled": disabled },
|
|
28
|
+
className
|
|
29
|
+
)}
|
|
30
|
+
>
|
|
31
|
+
<label>
|
|
32
|
+
<input
|
|
33
|
+
id={id}
|
|
34
|
+
type="checkbox"
|
|
35
|
+
data-test={testHook}
|
|
36
|
+
checked={checked}
|
|
37
|
+
onChange={onChange}
|
|
38
|
+
disabled={disabled}
|
|
39
|
+
/>
|
|
40
|
+
<div className="custom">
|
|
41
|
+
{checked && <FontAwesomeIcon icon={faCheck} />}
|
|
42
|
+
</div>
|
|
43
|
+
<div className="label">{label}</div>
|
|
44
|
+
</label>
|
|
45
|
+
</div>
|
|
46
|
+
)
|
|
47
|
+
}
|