Skip to content

Commit

Permalink
Merge pull request #8388 from google/enhancement/8137-add-info-notice
Browse files Browse the repository at this point in the history
Add AudienceSegmentation/InfoNotice
  • Loading branch information
techanvil committed Mar 15, 2024
2 parents 5b8525c + c85262b commit a0ea3d1
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* InfoNotice component.
*
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* Internal dependencies
*/
import { Button } from 'googlesitekit-components';
import LightbulbIcon from '../../../../../../svg/icons/lightbulb.svg';

export default function InfoNotice( { content, dismissLabel, onDismiss } ) {
return (
<div className="googlesitekit-audience-segmentation-info-notice">
<LightbulbIcon width="20" height="20" />
<div className="googlesitekit-audience-segmentation-info-notice__body">
<p>{ content }</p>

{ dismissLabel && (
<Button
tertiary
onClick={ onDismiss }
className="googlesitekit-audience-segmentation-info-notice__dismiss"
>
{ dismissLabel }
</Button>
) }
</div>
</div>
);
}

InfoNotice.propTypes = {
content: PropTypes.string.isRequired,
dismissLabel: PropTypes.string,
onDismiss: PropTypes.func,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* InfoNotice Component Stories.
*
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import InfoNotice from './InfoNotice';

function Template( args ) {
return <InfoNotice { ...args } />;
}

export const Default = Template.bind( {} );
Default.storyName = 'Default';

Default.args = {
content:
'The higher the portion of new visitors you have, the more your audience is growing. Looking at what content brings them to your site may give you insights on how to reach even more people.',
dismissLabel: 'Got it',
};
Default.scenario = {
label: 'Modules/Analytics4/Components/AudienceSegmentation/InfoNotice/Default',
};

export default {
title: 'Modules/Analytics4/Components/AudienceSegmentation/InfoNotice',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* EnhancedMeasurementSwitch tests.
*
* Site Kit by Google, Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import { render } from '../../../../../../../tests/js/test-utils';
import InfoNotice from './InfoNotice';

describe( 'InfoNotice', () => {
it( 'should render correctly in the default state', () => {
const { container, getByText } = render(
<InfoNotice
content="Test content"
dismissLabel="Test dismiss label"
/>
);

expect( container ).toMatchSnapshot();
expect( getByText( 'Test content' ) ).toBeInTheDocument();

expect( getByText( 'Test dismiss label' ) ).toBeInTheDocument();
} );

it( 'should invoke the onDismiss callback when clicked', () => {
const onClick = jest.fn();

const { getByText } = render(
<InfoNotice
content="Test content"
dismissLabel="Test dismiss label"
onDismiss={ onClick }
/>
);

const button = getByText( 'Test dismiss label' );

button.click();

expect( onClick ).toHaveBeenCalledTimes( 1 );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InfoNotice should render correctly in the default state 1`] = `
<div>
<div
class="googlesitekit-audience-segmentation-info-notice"
>
<svg />
<div
class="googlesitekit-audience-segmentation-info-notice__body"
>
<p>
Test content
</p>
<button
class="mdc-button googlesitekit-audience-segmentation-info-notice__dismiss mdc-button--tertiary"
target="_self"
>
<span
class="mdc-button__label"
>
Test dismiss label
</span>
</button>
</div>
</div>
</div>
`;
1 change: 1 addition & 0 deletions assets/sass/components/analytics-4/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
@import "googlesitekit-analytics-setup-module";
@import "googlesitekit-analytics-enhanced-measurement";
@import "audience-segmentation/googlesitekit-audience-segmentation-setup-cta";
@import "audience-segmentation/googlesitekit-audience-segmentation-info-notice";
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.googlesitekit-audience-segmentation-info-notice {
align-items: center;
background-color: $c-surfaces-surface;
border-radius: $br-sm;
display: flex;
gap: 20px;
justify-content: space-between;
padding: $grid-gap-phone;

@media (min-width: $bp-desktop) {
padding: $grid-gap-phone 40px;
}

svg {
color: $c-yellow-y-100;
flex-shrink: 0;
}
}

.googlesitekit-audience-segmentation-info-notice__body {
align-items: center;
display: flex;
flex-grow: 1;
flex-wrap: wrap;
gap: 0 60px;
min-width: 0;

p {
flex-basis: 400px;
flex-grow: 1;
}
}

.googlesitekit-audience-segmentation-info-notice__dismiss {
flex-shrink: 0;
margin-left: auto;
}
3 changes: 3 additions & 0 deletions assets/svg/icons/lightbulb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a0ea3d1

Please sign in to comment.